设为首页 加入收藏

TOP

Web服务的调用
2019-09-02 23:56:17 】 浏览:16
Tags:Web 服务 调用

 

1.创建服务引用

例如:天气预报

 

2.在代码添加引用空间

1   TvProgram.ChinaTVprogramWebService tp = new TvProgram.ChinaTVprogramWebService();
2         DataSet ds=    tp.getAreaDataSet();
View Code

 3.引用具体方法

 1  private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
 2         {
 3             ComboBox cb = (ComboBox)sender;
 4             if(comboBox1.SelectedIndex>0)
 5             { 
 6            
 7              int num= Convert.ToInt32(cb.SelectedValue.ToString());
 8 
 9              TvProgram.ChinaTVprogramWebService tp = new TvProgram.ChinaTVprogramWebService();
10              DataSet ds = tp.getTVstationDataSet(num);
11              comboBox2.DataSource = ds.Tables[0];
12              comboBox2.DisplayMember = "tvStationName";
13              comboBox2.ValueMember = "tvStationID";
14            
15             }
16         }

 

返回的xml用两种处理方法

  //DataRow[] dt = ds.Tables[0].Select();   
       //for (int i = 3; i < dt.Length; i++)
       //{
       //    Text = dt[i]["Area"].ToString();
       //   Value = Convert.ToInt32(dt[i]["areaID"].ToString());
        //    comboBox1.Items.Add(Text);
       //}
       
 comboBox1.DataSource = ds.Tables[0];
        comboBox1.DisplayMember = "Area";
        comboBox1.ValueMember = "areaID";

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇多线程编程学习笔记——任务并行.. 下一篇CLR via C# 读书笔记-26.线程基础

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目