ASP.NET 调用 webservice

使用Asp.Net  (C#)调用互联网上公开的WebServices(http://www.webxml.com.cn/WebServices/WeatherWebService.asmx)来实现天气预报,该天气预报 Web 服务,数据来源于中国气象局 http://www.cma.gov.cn/ 

ASP.NET 调用 webservice

步骤 :

1 、新建空web 项目,添加窗体defualt。ASP.NET 调用 webservice

2 、 引用右键--> 添加服务引用-->高级--> 添加Web引用。

ASP.NET 调用 webservice

ASP.NET 调用 webservice


ASP.NET 调用 webservice


注意添加引用的WEB应用名,方法里要调用  WeatherService.WeatherWebService w = new WeatherService.WeatherWebService();

ASP.NET 调用 webservice


ASP.NET 调用 webservice

protected void bt_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];


        }