ASP. NET uses WebService to implement the weather forecast function. asp. netwebservice
In this paper, Asp. Net (C #) is used to call the Web Services (http://www.webxml.com.cn/WebServices/WeatherWebService.asmx) published on the Internet to achieve weather forecast. The weather forecast Web Service data comes from the China Meteorological Administration http://www.cma.gov.cn/, and the data is automatically updated every hours. Including weather forecast data for over 340 major Chinese cities and over 60 major foreign cities within three days.
:
Steps:
1. Create a web project and add a form.
2. Right-click the reference and choose add service reference> advanced> Add Web reference.
3. Copy the Web interface to the box on the right of the URL --> click the arrow on the right of the input box to test the connection (check whether the connection is successful in the lower left corner) --> you can change the Web reference name on the rightmost side --> Add a reference.
Front-end code
<Div> <br/> Asp. net call WebService to implement weather forecast <br/> enter the 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/> <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/> weather conditions: <br/> <asp: textBox ID = "txtcityweather" runat = "server" Height = "62px" TextMode = "MultiLine" Width = "258px"> </asp: textBox> <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 all the content of this article. I hope it will be helpful for your learning and support for helping customers.