.net 项目中应用Web Services(vs2012)

一、在asp.net项目中添加Web services
1、新建一个asp.net项目(目前尚未验证是否可以在MVC项目中添加)
2、在项目名上右击,选择添加→新建项→Web服务,输好名称后确定即可


二、在asp.net项目中使用Web Services
1.在项目中添加对web services的引用
 方法:在“引用”上右击,选择“添加服务引用”,在地址中输入web service的地址,在本例中输入的是“http://www.webxml.com.cn/WebServices/WeatherWebService.asmx”,输入完后点击确定

2.在代码中调用 
 protected void btnSubmit_Click(object sender, EventArgs e)
        {
            WeatherWebServiceSoapClient wwsc = new WeatherWebServiceSoapClient();
            string[] result = wwsc.getWeatherbyCityName(this.txtCityName.Text);
            CityName.Text = result[0] + result[1];
            Temperature.Text = result[5];
        }

 

posted @ 2015-01-19 19:01  astrue  阅读(207)  评论(0)    收藏  举报