Learn how to get weather detail using Web Services in ASP.NET?
Another one important question I saw in the forum section how to get weather detail of my city using web services. Here I explained how to get weather details of your city or any other city in the world using web services.
Here in this example project I keep the two drop down list one for country and another one for city. After you select country automatically that country cities are loaded in the second drop down list you can select city and click the submit button that all you will get your selected city weather details.
protected void Button1_Click(object sender, EventArgs e)
Label1.Text = "";
Label2.Text = "";
if ((DropDownList1.SelectedIndex == 0) || (DropDownList2.SelectedIndex == 0))
string xmlResult = null;
url = "http://www.webservicex.net/globalweather.asmx/GetWeather?CityName=" + DropDownList2.SelectedItem + "&CountryName=" + DropDownList1.SelectedItem + "";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader resStream = new StreamReader(response.GetResponseStream());
XmlDocument doc = new XmlDocument();
xmlResult = resStream.ReadToEnd();
XmlDocument xl = new XmlDocument();
XmlNodeList xnList = xl.SelectNodes("CurrentWeather");
foreach (XmlNode xn in xnList)
Label1.Text = "Temperature : " + xn["Temperature"].InnerText;
Label2.Text = "Humidity : " + xn["RelativeHumidity"].InnerText;
Label1.Text = "City Name Not match with our site!";
Label2.Text = "";
Source Code Detail:
Here with i have attached entire source code. Download it and try to check your city weather detail using web services.
Front End : ASP.NET
Code Behind : C#
Note : If you add any country in the first drop down list please check the exact country name in the XML file (placed in the same project source file name as Country.XML) and add it to the drop down list.
The Weather is not common for all cities it is different in all places, using this project we can check or test our city weather details. I hope this one is help you to find out weather report.
what ever cities name given by www.webservicex.net that only load in the dropdownlist.
I have to display weather information for today,tomorrow and day after tomorrow.
Now i able to see present temperature only
How to get weather information for tomorrow and day after tomorrow?
Hi... It is working fine.. Thanks for the post... Could any one tell me how to set default Country/city on DropDownList by help of login ip.
Where can I download the source code again? There isn't any download link available. btw, this is a very helpful post. Keep up the good work.