您的位置:首页 > 编程语言 > C#

C#调用WebService实现天气预报

2013-05-03 09:36 369 查看
实现步骤:

1、引入Web服务。在VS中项目上右击→添加服务引用。



 

2、在弹出的添加服务引用窗口,录入web服务地址和引用后的命名空间。





 

3.核心代码如下:

 

<form id="form1" runat="server">

    <div>

   

        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="查询" />

        <br />

        <asp:Label ID="Label1" runat="server" Text="天气概况"></asp:Label>

        :<asp:Label ID="Label2" runat="server"></asp:Label><asp:Image ID="Image1"

            runat="server" Height="40px" Width="42px" />

        <br />

        <br />

        <asp:Label ID="Label3" runat="server" Text="天气实况"></asp:Label>

        :<asp:TextBox ID="TextBox2" runat="server" Height="131px" Width="325px"></asp:TextBox></div>

    </form>

 

 

4、天气图标可至【http://www.webxml.com.cn/images/weather.zip】下载。

5、Web服务的各方法参数直接访问【http://www.webxml.com.cn/WebServices/WeatherWebService.asmx】查询,从而实现其它丰富功能,如未来天气预报等。

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: