3

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

1 Answer 1

6

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
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Keith I will test this out in the morning

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.