Invoking a SOAP-based Web Service with PowerShell

by kevin 5/18/2008 10:45:00 PM

When I was at the NOVA Code Camp 2008.1 on Saturday, during one of my presentations, a question came up about using my ProxyForWsdl class (which I am now calling SuperSOAP, by the way) to invoke a SOAP-based web service from PowerShell. Nothing could be easier. This simple script would invoke the FactorService that I demonstrated during the talk to get the prime number integer factors of the number 8,675,303:

1: [Reflection.Assembly]::LoadFile( "<Path Omitted>\ProxyForWsdl.dll" )
2: $client = [gotnet.biz.ProxyGen.WsdlHelper]::GenerateProxyObjectForService( "http://<Server Omitted>/FactorService.asmx?WSDL", "FactorServiceSoap12" )
3: $client.GetIntegerFactors( 8675303 )

Line 1 loads the ProxyForWsdl assembly into PowerShell. Line 2 generates a dynamic proxy object for the FactorService based on the service's WSDL and a known endpoint named FactorServiceSoap12 (described in the WSDL). The PowerShell variable holding the proxy reference is named $client. Line 3 invokes the remote GetIntegerFactors web service method through $client with the parameter 8675303. The output of this script is:

7
7
13
13619

These are the prime number factors of the integer 8,675,303 just as you would expect. The service invocation worked! To build the ProxyForWsdl assembly referenced in the PowerShell script:

  • Download my ProxyGen source code and unzip it
  • The TestHarness project in the ProxyGen solution uses IronPython but you don't need it. Either remove the TestHarness project or download IronPython 2.0 (or later) and fix up the references to the IronPython, IronPython.Modules and Microsoft.Scripting assemblies to make the solution build. I recommend downloading IronPython, of course, because the TestHarness has some interesting code in it that shows how you can use C# code to host a PythonEngine. This can come in handy for injecting scriptlets into C#. The combination of languages feels good to me. C# for its wonderful retentiveness and Python for its equally wonderful expulsiveness.
  • Build the project and note the location of the ProxyForWsdl.dll assembly. You'll need that path in the PowerShell script shown above.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , ,

User Group | PowerShell

Powered by BlogEngine.NET 1.3.1.0
Theme by Mads Kristensen


Kevin's on Twitter / FriendFeed

W. Kevin Hazzard Welcome to Kevin Hazzard's Blog. Kevin is a Software Architect, Professor and Microsoft MVP specializing in C#, WCF, Silverlight and IronPython.

View Kevin Hazzard's profile on LinkedIn
Microsoft MVP Award When a problem comes along, you must flip it!

Calendar

<<  August 2008  >>
MoTuWeThFrSaSu
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567

View posts in large calendar

Recent comments

Authors

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

Sign in