Windows Powershell: Invoking a Web Service
About a year ago I posted about invoking a Web Service using Windows Powershell v3 CTP 1. Powershell v3 is the standard on Windows 8 and Windows 2012 Server. However, I learned that you don’t need to use v3, because there is a very nice cmdlet one can use to invoke Web services through a proxy object. It’s called New-WebServiceProxy.So here is the example of invoking a stock quote Web service using powershell with the proxy cmdlet:
- $URI = "http://www.webservicex.net/stockquote.asmx?WSDL"
- $stock = New-WebServiceProxy -uri $URI
- $xml = [xml]$stock.getQuote("MSFT")
- $xml.StockQuotes.Stock
On the above example I invoked the “getQuote” method. After instantiating the proxy on the $stock variable, if you’d like to learn what methods are available, as well as the parameters and return types, you can type at the prompt:
- $stock | get-member -type method
Happy coding!
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment