I'm using PowerShell V2 and trying to find an example of using a web service proxy to call an asynchronous web method:
Here is the code I have so far:
$Uri = "http://localhost/mywebservice.asmx?wsdl"
$proxy = New-WebServiceProxy -Uri $Uri -UseDefaultCredential
The web services has the following methods BeginFoo EndFoo FooAsync *FooCompleted*
Hopefully this makes sense
Here's an example of using BeginInvoke/EndInvoke. Run $ar | Get-Member to see what other methods and properties are available to you on the IAsyncResult object.
PS> $zip = New-WebServiceProxy -uri http://www.webservicex.net/uszip.asmx?WSDL
PS> $ar = $zip.BeginGetInfoByAreaCode("970", $null, $null)
... other PS script ...
# Now join the async work back to the PowerShell thread, wait for completion
# and grab the result. WaitOne returns false on timeout, true if signaled.
PS> $ar.AsyncWaitHandle.WaitOne([timespan]'0:0:5')
True
PS> $ar.IsCompleted
True
PS> $res = $zip.EndGetInfoByAreaCode($ar)
PS> $res.Table
CITY : Whitewater
STATE : CO
ZIP : 81527
AREA_CODE : 970
TIME_ZONE : M
CITY : Wiggins
STATE : CO
ZIP : 80654
AREA_CODE : 970
TIME_ZONE : M
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With