Monday, October 20, 2008

SilverLight 2 [Calling Weather WebService]

Silverlight client calling the following Weather Service http://www.webservicex.net/WeatherForecast.asmx

1) Create VS.NET 2008 Silverliight Appliciaton

2) This will create or Add two projects into solution. one is SilverLight UI project and Testing project which has both .ASPX and HTML pages.

3) The above webService expose the following two web methods
GetWeatherByPlaceName Get one week weather forecast for a place name(USA) GetWeatherByZipCode Get one week weather forecast for a valid Zip Code(USA)
In this project i am using Get WeatherInfo by Zipcode using HTTP-GET method.

4) To Invoke the above webservice we need to use the WebClient class from the follwoing .NET assembly System.Data.Services.Client.dll .

5) GetWeatherByZipCode method returns XML data which has Weekly weather information as shown below.





using LINQ to XML Parse the XML Data and create the WeatherData .NET UDT (user defined Type ) object.


public class WeatherData
{
public string day { get; set; }
public string urlImage { get; set; }
public string maxTemp { get; set; }
public string minTemp { get; set; }
}














Thanks

Seenivasaragavan




















1 comment:

Kemi Online said...

Does not work...can you please post the source code?

Thanks.