开发者

How do I access a web service from PowerShell?

开发者 https://www.devze.com 2022-12-16 04:59 出处:网络
I\'d like to access a web service with a given (simple) WSDL from within Windows PowerSh开发者_如何学Goell.

I'd like to access a web service with a given (simple) WSDL from within Windows PowerSh开发者_如何学Goell.

Is there an easy way to do this?


# Working example of how to use PowerShell (version >= 2) to access a web service.
$svc = New-WebServiceProxy –Uri ‘http://www.webservicex.net/stockquote.asmx?WSDL’

$svc | Get-Member  # Use Get-Member to discover the interface of a web service.
# Get stock quotes. 
$svc.GetQuote(‘BA’)   # Boeing
$svc.GetQuote(‘AMZN’) # Amazon
$svc.GetQuote(‘SBUX’) # Starbucks


One way would be to use WSDL.exe to generate wrapper classes - compile the generated source and use the strongly typed classes from PowerShell. The whole generate - compile - instantiate process can be easily done automatically from PowerShell.

If you are using PowerShell 2.0, use New-WebServiceProxy as suggested in the other answer.

0

精彩评论

暂无评论...
验证码 换一张
取 消