Extracting data from a web service
In this recipe, we will extract data from a free, public web service.
How to do it...
Let's explore how to access and retrieve data from a web service:
- Open PowerShell ISE as an administrator.
- Add the following script and run it:
#delayed stock quote URI $stockUri = "http://ws.cdyne.com/delayedstockquote/delayedstockquote.asmx" $stockproxy = New-WebServiceProxy -Uri $stockUri -UseDefaultCredential #get quote $stockresult = $stockProxy.GetQuote("MSFT","") #display results $stockresult.StockSymbol $stockresult.DayHigh $stockresult.DayLow $stockresult.LastTradeDateTime
How it works...
To work with a web service, we first need to create a proxy object that will allow us to access the methods available in a web service. We can achieve this using the New-WebProxy
cmdlet, which accepts the web service URI:
$stockUri = "http://ws.cdyne.com/delayedstockquote/delayedstockquote.asmx"
This URI points to a free web service that...