Dec 22, 2008

Call WCF Services With PowerShell

Call WCF Services with PowerShell using any binding. Generates proxies on the fly without any tool expect .NET 3.5. You can also discover the service endpoints, bindings and contracts.
  • The PS2WCF script
Download sample WCF Hello Service project and start ConsoleShell
  • Meatdata discovery:

$wsdl = Get-WsdlImporter -wsdlUrl "net.tcp://localhost:8888/HelloService/mex" $wsdl.ImportAllEndpoints() | format-list



Note: For none mex endpoints use: Get-WsdlImporter -wsdlUrl http://anyurl/service.svc?wsdl –httpGet $true

  • Generate the WCF proxy

$proxyTypes = Get-WcfProxy -wsdlUrl "net.tcp://localhost:8888/HelloService/mex"


$proxyTypes = Get-WcfProxy –wsdlImporter $wsdl

$proxyTypes | format-table



  • Call a service operation

$address = New-Object System.ServiceModel.EndpointAddress("net.tcp://localhost:8888/HelloService/")

$binding = new-object System.ServiceModel.NetTcpBinding

$proxy = New-Object $proxyTypes -ArgumentList $binding, $address


or use bindings and addresses generated from WsdlImporter

$endpoints = $wsdl.ImportAllEndpoints()

$proxy = New-Object $proxyTypes($endpoints[0].Binding, $endpoints[0].Address)




By Christian Glessner


Steven Murawski said...

Very cool script. I've been meaning to put something like this together for a while. I'll put it to good use. :)

Merry Christmas!

Anonymous said...

I am new to the power shell. I just tried out the below example to get the returen values.
I am able to get the value of 'SayHello'. but how do I do it for 'SayHelloWithDataContract'

public interface IHello
string SayHello(string name);

[OperationContract(Action = "SayHelloWithDataContract")]
string SayHelloWithDataContract(TestDataContract testDataContract);

public class TestDataContract
public TestDataContract(string FirstName1, string LastName1)
FirstName = FirstName1;
LastName = LastName1;

public string FirstName;
public string LastName;



Anonymous said...

I did run into problems when using the above syntax that relies on implicit conversion of the $proxyTypes object:

$proxy = New-Object $proxyTypes -ArgumentList $binding, $address

Using the more explicit object properties for PowerShell 2.0solved the issue for me:

$proxy = New-Object $proxyTypes.FullName -ArgumentList $binding, $address

zippy1981 said...

I just discovered you script. Thanks for writing it.

I have updated it to PowerShell version 2.0. Thanks a lot for writing it.

Also, I change the function Get-WcfProxy to Get-WcfProxyType and added a function called Get-WcfProxy that behaves like Get-WebServiceProxy.

What license is this code released under?

zippy1981 said...

My powershell 2.0 version of the code:

Christian said...

Thanks for creating the V2.0 :D
License: none. Just happy if you mention me.
Bye, Christian

zippy1981 said...

Github for my fork here: A blog explaining my changes:

Also not mentioned is I added a -Timeout flag to Get-WcfProxy

Eoin said...

Hi Christian, Excellent little tool but I'm running into a small problem with it. It would seem I'm only able to call the following script once per session.

$wsdl = Get-WsdlImporter -wsdlUrl "http://localhost/TestService/Service.svc?wsdl" –httpGet $true
$proxyTypes = Get-WcfProxy –wsdlImporter $wsdl
$endpoints = $wsdl.ImportAllEndpoints()
$proxy = New-Object $proxyTypes($endpoints[0].Binding, $endpoints[0].Address)
$proxy.DoWork("Hello World")

It would seem to have something to do with the On-the-fly compilation of the proxy object.

Running that script the first time in a PS Console is fine. But if I run it a second time, I get

New-Object : Cannot find type [ServiceClient, 2hazj94y, Version=, Culture=neutral, PublicKeyToken=null]: make sure the assembly containing this type is loaded.
At D:\Work\Sandbox\Powershell\CallWebService2.ps1:4 char:20

Any ideas ?


Anonymous said...

How do you use this nonWCF services which does not define MEX endpoints?
I also posted this in the PowerShell forum:

digital signature said...

Congratulations, your blog is appealing and informative. Going through your Information, I found quite a few new ideas to implement.

Sarah Urmeneta said...
This comment has been removed by the author.
Anonymous said...

How do you pass a complex type parameter to the service operation?

replica chanel handbags said...

I dropped a quick note here on the blog to let you all know of this bag’s availability online, and then I’m off to the meetings here in rainy Milan before Fashion Week in the city officially begins tomorrow.

سما احمد said...

تنظيف خزانات بمكة
تنظيف شقق بالدمام
تنظيف منازل بالدمام
تسليك مجاري بالدمام
رش مبيدات بالدمام
كشف تسربات المياه بالدمام

شركة تنظيف مسابح بالرياض
شركة تنظيف موكيت بالرياض
شركة تنظيف مجالس شرق الرياض
شركة رش مبيدات بالرياض
شركة تنظيف خزانات شرق الرياض
شركة الصفرات لمكافحة الحشرات بالرياض
شركة تنظيف شقق شرق الرياض
شركة نقل اثاث شرق الرياض
شركة تنظيف بيوت بالرياض
شركة تنظيف منازل شرق الرياض
شركة الصفرات لتنظيف الفلل
شركة نقل عفش بالرياض
شركة تنظيف منازل بالرياض
شركة مكافحة النمل الابيض بالرياض
شركة تنظيف موكيت بالخرج
شركة عزل خزانات بالرياض
شركة تنظيف خزانات بالمدينة المنورة

سما احمد said...

شركة تنظيف بالرياض
شركة جلي بلاط بالرياض
شركة تسليك مجارى بالرياض
تنظيف ستائر بالرياض

شركة تنظيف مساجد بالرياض
شركة كشف تسربات المياه بالرياض
تنظيف أنابيب الصرف الصحي
شركة تنظيف بالبخار
شركة تنظيف رخام بالرياض
شركة تنظيف زجاج الابراج

شركة تنظيف بيوت الشعر بالرياض

شركة الصفوة

ديكورات غرف نوم
تنظيف خزانات بالدمام
تنظيف خزانات بجدة

سما احمد said...

شركة مكافحة حشرات بالرياض

شركة شراء الاثاث مستعمل بالرياض
شركة تنظيف شمال الرياض
شركة تنظيف شرق الرياض
شركة عزل اسطح بالرياض
شركة تنظيف شقق بالرياض
شركة تنظيف موكيت بالرياض
شركة تنظيف مجالس بالرياض
شركة تنظيف منازل بالرياض
شركة تنظيف بالرياض
شركة تنظيف فلل بالرياض
شركة عزل خزانات غرب الرياض
شركة جلي بلاط بالرياض
شركة تنظيف خزانات الرياض

سما احمد said...

شركة مكافحة النمل الابيض بالرياض
شركة تنظيف واجهات حجر بالرياض
شركة تخزين عفش بالرياض
شركة تنظيف مسابح بالرياض
شركة تنظيف واجهات زجاج بالرياض
شركة نقل اثاث بالرياض
شركة تنظيف خزانات بالخرج

Kumar Vikal said...

Happy Ganesh Chaturthi SMS
Ganesh Chaturthi SMS in Hindi
Ganesh Chaturthi SMS in Marathi, Hindi
Ganesh Chaturthi in Marathi Language, SMS, Wishes, Quotes, Messages
Ganpati Bappa SMS in Hindi, Marathi, Ganesh Chaturthi SMS, Ganpati Bappa Quotes
Salman Khan Upcoming Movies
Android M Features
Xperia Z5 Specifications
Sultan Star Cast
Uncoming Hindi Movies 2016

Kumar Vikal said...

Gandhi Jayanti SMS
Happy Gandhi Jayanti
Gandhi Jayanti Images

Kumar Vikal said...

Happy Gurpurab
Guru Nanak Jayanti Images
Guru Nanak Jayanti
26 January Images
Hate Story 3 Zarine Khan
Hate Story 3 Hot Zarine Khan
Hot Zarine Khan in Hate Story 3