This article uses asp.net (C #) to invoke the public webservices (http://www.webxml.com.cn/WebServices/WeatherWebService.asmx) on the Internet to implement the weather forecast, which WEB services, data from the China Meteorological Bureau http://www.cma.gov.cn/, the data automatically updated every 2.5 hours, accurate and reliable. Including more than 340 major cities in China and more than 60 major foreign cities in the 3rd weather forecast data.
Effect Chart:
Steps:
1. Create a new Web project and add a form.
2, reference right key--> Add Service Reference--> advanced--> Add Web references.
3. Copy the Web interface to the box to the right of the URL--> click on the arrow to the right of the input box to test the connection (see the bottom left corner for connection success)--> rightmost can change the Web reference name--> Add Reference.
Front Code
<div> <br/> <br/> asp.net call WebService to implement the weather forecast <br/> <br/> <br/> nbsp; Please enter city name: <asp:textbox id= "txtcity" runat= "Server" ></asp:TextBox> <asp:label id= "Label1" runat= "Server" style= "color:red" bordercolor= "Red" text= "such as: Shanghai" ></asp:label > <br/> <br/> <asp:button id= "btncheck" runat= "server" text= "query" width= "69px" onclick= "btnCheck_Click"/> <br/> Weather Overview: <asp:label id= "Lbtianqi" runat= "Server" style= "bordercolor=" Red "text=" "></asp:label > <br/> <br/> Weather Facts: <br/> <asp:textbox id= "Txtcityweather" runat= "Server" height= " 62px "textmode=" MultiLine "width=" 258px "></asp:TextBox> <br/> & nbsp; <br/> <br/
> <br/> <br/> <br/> <br/> </div>
Background code
protected void btnCheck_Click (object sender, EventArgs e)
{
Weatherservice.weatherwebservice w = new Weatherservice.weatherwebservice ();
string [] res=new string[23];
String cityname = Txtcity. Text.trim ();
res = W.getweatherbycityname (cityname);
Lbtianqi. Text = CityName + "" +res[6];
Txtcityweather. Text = res[10];
}
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.