web-services - 使用 Powershell 在 Web 服务上调用异步 Web 方法

标签 web-services powershell

我正在使用 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/

相关文章:

python - 使用 django 的 heroku 不允许使用 405 POST 方法

powershell - 完全路径可执行文件时 PowerShell 中的“意外 token ”

Powershell 在模块内加载模块 [范围]

windows - 如何使用 Powershell 搜索 Windows 搜索索引文件

powershell - 如何使用参数将命令别名为同一命令?

.net - SOA : WCF 中转换层的替代方案

ios - 进行服务调用时如何设置输入参数

java - RESTful Web 服务如何正确生成 JSON?

Powershell ConvertTo-Json 缺少方括号并添加新字符

java - 生成 web 服务客户端时 Apache 意外的子元素异常