C#调用webservice(二)
生活随笔
收集整理的這篇文章主要介紹了
C#调用webservice(二)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
第二篇調用webservice,web服務是http://webservice.webxml.com.cn/webservices/DomesticAirline.asmx,航班查詢服務
添加web服務的方法是:在visual studio中的“解決方案管理器”的項目中有個“引用”,右擊“添加服務引用”,在對話框中輸入webservice的URL,點擊“前往”,再“確定”就好了。
此服務有兩個方法:?getDomesticAirlinesTime(string,string,string,string) ? ?//四個參數,返回DataSet
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?getDomesticCity() ? ?//無參數,返回DataSet
?
1.用了兩個listview來顯示結果
listview的使用:添加列標題
2.要用的命名空間:
1 using System.Net; 2 using System.Data;3.添加控件:
1 private void button3_Click(object sender, EventArgs e) 2 { 3 ServiceReference2.DomesticAirlineSoapClient ww = new ServiceReference2.DomesticAirlineSoapClient("DomesticAirlineSoap"); 4 DataSet s = new DataSet(); 5 s = ww.getDomesticAirlinesTime(textBox2.Text,textBox3.Text,textBox4.Text,string.Empty); 6 int RowCount = s.Tables[0].Rows.Count; 7 int ColumnCount = s.Tables[0].Columns.Count; 8 for (int i = 0; i < RowCount; i++) 9 { 10 string itemName = s.Tables[0].Rows[i][0].ToString(); 11 ListViewItem item = new ListViewItem(itemName, i); 12 //循環每一列 13 for (int j = 1; j < ColumnCount; j++) 14 { 15 item.SubItems.Add(s.Tables[0].Rows[i][j].ToString()); 16 } 17 listView1.Items.Add(item); 18 } 19 } 20 private void button4_Click(object sender, EventArgs e) 21 { 22 ServiceReference2.DomesticAirlineSoapClient ww = new ServiceReference2.DomesticAirlineSoapClient("DomesticAirlineSoap"); 23 DataSet s = new DataSet(); 24 s = ww.getDomesticCity(); 25 int RowCount = s.Tables[0].Rows.Count; 26 int ColumnCount = s.Tables[0].Columns.Count; 27 for (int i = 0; i < RowCount; i++) 28 { 29 string itemName = s.Tables[0].Rows[i][0].ToString(); 30 ListViewItem item = new ListViewItem(itemName, i); 31 //循環每一列 32 for (int j = 1; j < ColumnCount; j++) 33 { 34 item.SubItems.Add(s.Tables[0].Rows[i][j].ToString()); 35 } 36 listView2.Items.Add(item); 37 } 38 }4.最后結果:(和上一次的弄一起了)
?
轉載于:https://www.cnblogs.com/cjxy1993/p/4118306.html
總結
以上是生活随笔為你收集整理的C#调用webservice(二)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: FineUI 选中多行获取行ID
- 下一篇: 软件测试中常用的术语