ASP. NET uses WebService to implement the weather forecast function. asp. netwebservice

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.