• 简单的webservice调用(天气预报)


    1.新建一个项目

    2.邮件点击解决方案下的网站目录,选择“添加web引用”,输入web服务的网址,必须是以 asmx结尾的,且不带参数,(这里以http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx

    为例)然后前往---

    3.在web引用名  中的就是命名空间,有的是自动填好的,有的需要自己填写,然后在 程序里添加引用就行了·· 

    4。在程序里  添加 using cn.com.webxml.webservice;

    这样就可以了 实例化然后调用方法了,对了,还要看web服务商的“接口帮助文档”来查看有哪些方法可以调用

    接下来

    if (!Page.IsPostBack)
            {
                cn.com.webxml.webservice.WeatherWS weather = new WeatherWS(); //实例化一个类
                DataSet ds = weather.getRegionDataset();//调用getRegionDataset() 方法,返回的是一个dataset
                DropDownList1.DataTextField = "RegionName";// 字段名 这里获取的省份
                 DropDownList1.DataValueField = "RegionID";//字段名
                DropDownList1.DataSource = ds.Tables[0]; 绑定到dropdownlist 上
                DropDownList1.DataBind();
                GridView1.DataSource = ds.Tables[0].DefaultView;
                GridView1.DataBind();
              
            }

        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            cn.com.webxml.webservice.WeatherWS weather = new WeatherWS();
            //DataSet ds = weather.getRegionDataset();
            //DropDownList1.DataTextField = "RegionName";
            //DropDownList1.DataValueField = "RegionID";
            //DropDownList1.DataSource = ds.Tables[0];
            //DropDownList1.DataBind();
            //GridView1.DataSource = ds.Tables[0].DefaultView;
            //GridView1.DataBind();

           string[] arr = weather.getWeather(DropDownList2.SelectedItem.Text,"");//调用GetWeather 方法 参数1:城市,或者城市的ID,参数2:用户名,免费用户为空,这个方法返回的是string类型的一维数组
           Response.Write(arr[7].ToString() + @"img\weather\weather" + arr[10].ToString()); //根据开发文档,调去需要的数据
           Image1.ImageUrl =@"img\weather\weather\"+arr[10].ToString(); //天气图片,下载到本地,然后调用
           Image2.ImageUrl = @"img\weather\weather\" + arr[11].ToString();
           Image1.ToolTip = arr[7].ToString();

        }
        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            cn.com.webxml.webservice.WeatherWS weather = new WeatherWS();//根据省份获取,这个省份里的城市,然后绑定到dropdownlist2上
            Label1.Text = DropDownList1.SelectedItem.Text.ToString();
            DropDownList2.DataSource = weather.getSupportCityDataset(DropDownList1.SelectedValue.ToString());
            DropDownList2.DataTextField = "CityName";
            DropDownList2.DataValueField = "CityID";
            DropDownList2.DataBind();
        }

  • 相关阅读:
    C#代码也VB
    Flash/Flex学习笔记(9):ActionScript3.0与Javascript的相互调用
    原来Silverlight 4中是可以玩UDP的!
    Flash/Flex学习笔记(20):贝塞尔曲线
    Flash/Flex学习笔记(16):如何做自定义Loading加载其它swf
    AS3:让人叹为观止的Flash作品
    Flash/Flex学习笔记(10):FMS 3.5之Hello World!
    Flash/Flex学习笔记(12):FMS 3.5之如何做视频实时直播
    Flash/Flex学习笔记(28):动态文本的滚动控制
    Flash/Flex学习笔记(18):画线及三角函数的基本使用
  • 原文地址:https://www.cnblogs.com/tiancai/p/2175516.html
Copyright © 2020-2023  润新知