Calling web services from Powershell

This example will call a web service to get the weather.

First , create a reference to the web service.

$uri = “http://ws.cdyne.com/WeatherWS/Weather.asmx
$ws = New-WebServiceProxy -Uri $uri

To see what methods are available:

$ws | Get-Member -MemberType Method

To get the definition for the service:

($ws | Get-Member -Name GetCityWeatherByZIP).definition

To call the service to get all weather data for ZIP 30080 (Smyrna, GA):

$ws.GetCityWeatherByZIP(“30080”)

Or to just display certain pieces of information:

$Weather = $ws.GetCityWeatherByZIP(“30080”)
Write-Host “City: “$Weather.City.ToString()
Write-Host “Description: “$Weather.Description.ToString()
Write-Host “Temperature: “$Weather.Temperature.ToString()

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: