对于初学者来说,在vs2012环境中,大家有可能不知道Web References文件夹是如何来的,它是通过右击项目,选择其中的”添加服务引用“,如图所示:

之后,得到”添加服务引用“的页面,我也把图截了下来,如图:

再选择”高级“按钮,进入下图

根据上图的指示,在URL这栏输入互联网上公开的WebServices(http://www.easck.com/WebServices/WeatherWebService.asmx)来实现天气预报。这样就可以通过代码来获取用户输入城市的天气了。实现的效果图如下:

通过点击按钮,系统会输出用户所填城市的天气信息。后台代码如下:
- protected void Button2_Click(object sender, EventArgs e) {
- WebApplication1.cn.com.webxml.www.WeatherWebService ws = new WebApplication1.cn.com.webxml.www.WeatherWebService(); string[] r = ws.getWeatherbyCityName(this.TextBox4.Text);
- this.TextBox3.Text = ""; if (r == null)
- { this.TextBox3.Text = "无" + this.TextBox4.Text + "城市的天气信息";










