Did you know how easy it is to test a web service in Powershell? I think I can get used to this new tool.
Proof of concept
Here’s my script for checking the weather in powershell:
$uri = "http://www.webservicex.net/WeatherForecast.asmx?WSDL" $WeatherForecast = New-WebServiceProxy -uri $uri -UseDefaultCredential -namespace "WeatherForecast" $WeatherForecast.GetWeatherByZipCode(78247) $WeatherForecast.GetWeatherByZipCode(78247).details
This publicly available web service returns the lat, lon of a zip! Sweet. I can find other uses for that.
The details object returns the forecast for today and the next 5 days.
Get the Methods
To reuse, substitute your web service’s WSDL URI and use something like the following to check for existing methods available:
$WeatherForecast | get-member -type method
Reference
I got inspiration and code pieces from StackOverflow.com, Technet’s New-WebServiceProxy reference and a blog post by Keith Hill.
So it dynamically creates a web proxy from a published WSDL? Is this a SOAP web service or REST based? Is it returning JSON or XML? Can it do WS*?
Yes, the proxy is created automatically. The example script calls a SOAP based web service which is most likely for a WSDL. REST doesn’t really do WSDL but I’d love to see a REST example that was this simple. JSON is XML, but I’m not sure if this example service uses it.
Thanks for the comment!
-Tom