1、创建服务引用
例如:天气预报
2、在代码添加引用空间
TvProgram.ChinaTVprogramWebService tp=new TvProgram.ChinaTVprogramWebService(); DataSet ds=tp.getAreaDataSet();
3、引用具体方法
private void comBox1_SelectedIndexChanged(object sender,EventArgs e) { ComboBox cb=(ComboBox)sender; if(ComboBox1.SelectedIndex>0) { int num=Convert.ToInt32(cb.SelectedValue.ToString()); TvProgram.ChinaTVprogramWebService tp=new TvProgram.ChinaTVprogramWebService(); DataSet ds=tp.getTVstationDataSet(num); comboBox2.DataSource=ds.Tables[0]; comboBox2.DisplayMember="tvStationName"; comboBox2.ValueMember="tvStationID"; } }
返回的XML用两种处理方法
comboBox1.DataSource=ds.Tables[0];
comboBox1.DisplayMember="Area";
comboBox1.ValueMember="areaID";