This project is read-only.

Usage scenarios

  1. How to get location data for the area I'm interested in?
  2. How to get weather conditions for today?
  3. How to get weather for today using US Zip code?
  4. How to get weather forecast for following 2 days?
  5. How to call location search asynchronously?
  6. How can I change units system that I'm getting from weather.com service?
  7. How to retrieve promotional links?
  8. How to set 1 minute timeout for Weather.com.Client calls?

How to get location data for the area I'm interested in?


Before weather conditions data can be retrieved from the web service, we need to establish area (location) we are interested in. This short code snippet explains how it can be achieved.

WeatherClient client = new WeatherClient("[Partner Id here]", "[License Key here]");
List<Location> locations = client.GetLocation("Warsaw,Poland");


How to get weather conditions for today?

WeatherClient client = new WeatherClient("[Partner Id here]", "[License Key here]");
List<Location> locations = client.GetLocation("Warsaw,Poland");
Location location = locations[0];
CurrentWeatherInfo conditions = client.GetCurrentConditions(location);

How to get weather for today using US Zip code?

WeatherClient client = new WeatherClient("[Partner Id here]", "[License Key here]");
USZipCode zipCode = new USZipCode("20037");
CurrentWeatherInfo conditions = client.GetCurrentConditions(zipCode);

How to get weather forecast for following 2 days?


WeatherClient client = new WeatherClient("[Partner Id here]", "[License Key here]");
List<Location> locations = client.GetLocation("Warsaw,Poland");
Location location = locations[0];
//when querying service for 3 days, it will return information for today and 2 following days.
int days = 3;
ForecastWeatherInfo weatherForecast = client.GetWeatherForecast(location, days);

How to call location search asynchronously?


WeatherClient client = new WeatherClient("[Partner Id here]", "[License Key here]");
IAsyncResult result = client.BeginGetLocation("Warsaw,Poland",null, null);
//Do some work here
// Wait until the operation completes.
result.AsyncWaitHandle.WaitOne();
List<Location> locations = _client.EndGetLocation(result);

How can I change units system that I'm getting from weather.com service?


WeatherClient client = new WeatherClient("[Partner Id here]", "[License Key here]");
client.Units = UnitsSystem.Standard;
//or
_client.Units = UnitsSystem.Metric;

How to retrieve promotional links?


WeatherClient client = new WeatherClient("[Partner Id here]", "[License Key here]");
List<Location> locations = client.GetLocation("Warsaw,Poland");
Location location = locations[0];
CurrentWeatherInfo conditions = client.GetCurrentConditions(location);
PromoLink firstPromoLink = conditions.PromotionalLinks[0];
//firstPromoLink.Position
//firstPromoLink.Title
//firstPromoLink.Url.AbsolutePath

How to set 1 minute timeout for Weather.com.Client calls?


WeatherClient client = new WeatherClient("[Partner Id here]", "[License Key here]");
client.Timeout = TimeSpan.FromMinutes(1);
List<Location> locations = client.GetLocation("Madrid,Spain") 

Last edited Jul 6, 2011 at 8:03 PM by mulawam, version 6

Comments

No comments yet.