使用 Powershell 在 Web 服务上调用异步 Web 方法 [英] using Powershell to call asynchronous web methods on a web service
本文介绍了使用 Powershell 在 Web 服务上调用异步 Web 方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 PowerShell V2 并试图找到一个使用 Web 服务代理调用异步 Web 方法的示例:
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
web services有以下方法BeginFooEndFooFooAsync*FooCompleted*
The web services has the following methods BeginFoo EndFoo FooAsync *FooCompleted*
希望这是有道理的
推荐答案
以下是使用 BeginInvoke/EndInvoke 的示例.运行 $ar |Get-Member
以查看您可以在 IAsyncResult 对象上使用哪些其他方法和属性.
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
这篇关于使用 Powershell 在 Web 服务上调用异步 Web 方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文