ASP.NET Web Services tutorial
Lección 12 de 13 · Part 7 Real time example of calling live weather forecast web service · Bases de datos
Part 7 Real time example of calling live weather forecast web service
Link for code samples used in the demo
http://csharp-video-tutorials.blogspot.com/2013/11/part-7-real-time-example-of-calling_13.html
Link for all dot net and sql server video tutorial playlists
http://www.youtube.com/user/kudvenkat/playlists
In this video we will discuss calling a LIVE weather forecast web service. The following is the URL of the real live web service. At the moment, this web service can only be used with US zip codes. There are 3 web methods in this web service. We will use GetCityWeatherByZIP method.
http://wsf.cdyne.com/WeatherWS/Weather.asmx
This web service can be used, if you want to display specific US city weather on your web site. Once we enter a ZIP code and when we click Get Weather button, we want to invoke the weather web service and display weather information of the provided zip code.
Here are the steps to consume this web service in an asp.net web application
Step 1: Create a new asp.net empty web application and name it WebServicesDemo.
Step 2: Right click on References folder in the WebServicesDemo project and select Add Service Reference option.
Step 3: In the Address textbox of the Add Service Reference window, type the below web service address and click GO button. In the namespace textbox type WeatherService and click OK.
http://wsf.cdyne.com/WeatherWS/Weather.asmx
Step 4: Right click on WebServicesDemo project in solution explorer and add new webform.
Step 5: Copy and past the HTML from my blog.
Step 6: Copy and past the following code on WebForm1.aspx.cs
using System;
namespace WebServicesDemo
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void btnGetWeather_Click(object sender, EventArgs e)
{
WeatherService.WeatherSoapClient client = new WeatherService.WeatherSoapClient(“WeatherSoap”);
WeatherService.WeatherReturn result = client.GetCityWeatherByZIP(txtZip.Text);
if (result.Success)
{
lblError.Text = “”;
lblCity.Text = result.City;
lblState.Text = result.State;
lblTemperature.Text = result.Temperature;
lblWind.Text = result.Wind;
lblWeatherStationCity.Text = result.WeatherStationCity;
}
else
{
lblError.Text = result.ResponseText;
lblCity.Text = “”;
lblState.Text = “”;
lblTemperature.Text = “”;
lblWind.Text = “”;
lblWeatherStationCity.Text = “”;
}
}
}
}