2012-06-20 165 views
2

我使用的PowerShell V2,并试图找到使用Web服务代理调用异步Web方法的一个例子:使用PowerShell来调用Web服务的异步Web方法

这里是我有这样的代码远:

$Uri = "http://localhost/mywebservice.asmx?wsdl" 

$proxy = New-WebServiceProxy -Uri $Uri -UseDefaultCredential 

Web服务有以下方法 BeginFoo EndFoo FooAsync * FooCompleted *

希望这是有道理的

回答

5

下面是使用的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 
+0

谢谢Keith我会在早上测试一下 – JasonHorner