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.