Asp. NET uses WebService to realize weather forecast function _ Practical skill

Source: Internet
Author: User

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.

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.