我正在使用 PowerShell V2 并试图找到一个使用 Web 服务代理调用异步 Web 方法的示例:
这是我目前的代码:
$Uri = "http://localhost/mywebservice.asmx?wsdl"
$proxy = New-WebServiceProxy -Uri $Uri -UseDefaultCredential
网络服务有以下方法 BeginFoo EndFoo FooAsync *FooCompleted*
希望这是有道理的
最佳答案
这是使用 BeginInvoke/EndInvoke 的示例。运行 $ar | Get-Member
查看 IAsyncResult 对象上还有哪些其他方法和属性可供您使用。
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
关于web-services - 使用 Powershell 在 Web 服务上调用异步 Web 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11111490/