PowerShell 2.0: One Cmdlet at a Time 26 New-WebServiceProxy
Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the New-WebServiceProxy cmdlet.
What can I do with it?
Make use of an available web service.
Examples:
The website http://www.webservicex.net has a number of available web services which you can use with the New-WebServiceProxy cmdlet.
Find the current weather for Southampton, UK.
$weather = New-WebServiceProxy -uri “http://www.webservicex.net/globalweather.asmx?wsdl" $weather.GetWeather(‘Southampton’, ‘United Kingdom’)
Note: to find what cities were available within the UK to query I used the GetCitiesByCountry method.
$weather.GetCitiesByCountry(‘United Kingdom’)
Find the location for the UK postcode SW1A.
$postcode = New-WebserviceProxy -uri “http://www.webservicex.net/uklocation.asmx?wsdl" $postcode.GetUKLocationByPostcode(‘SW1A’)
Return the words from Bible verse John, Chapter 3, 16.
$bibleverse = New-WebServiceProxy -uri “http://www.webservicex.net/BibleWebservice.asmx?wsdl" $bibleverse.GetBibleWordsByChapterAndVerse(‘John’,‘3’,‘16’)
There are many more web services available from http://www.webservicex.net which are fun to try out. You also may find other available webservices on the Internet or within your own organisation.
How could I have done this in PowerShell 1.0?
Lee Holmes from the PowerShell team has put together a Connect-WebService script you can use when working with PowerShell 1.0 to make use a web service. By using this script you can follow a similar process to the earlier examples.
$weather = .\Connect-WebService.ps1 “http://www.webservicex.net/globalweather.asmx?wsdl" $weather.GetWeather(‘Southampton’, ‘United Kingdom’)
I reckon that’s about 100 lines of code in a script down to one nice easy cmdlet when using the New-WebServiceProxy cmdlet. Nice!