然后编写Windows客户端和Web客户端消费该服务
2024-07-21 02:27:40
供稿:网友
为了体现xmlwebservice的可跨越异质平台、与系统无关与设备无关与消费者的应用程序类型无关等特性。
给学生演示了用c#编写一个windows程序来消费该服务的例子:
代码很简单,只是添加如下几行而已:
private void button1_click(object sender, system.eventargs e)
{
get.service1 aa=new ws03.get.service1();
string score=aa.getscore(combobox1.selecteditem.tostring(),combobox2.selecteditem.tostring()).tostring();
label3.text="学生"+combobox1.selecteditem.tostring()+"的"+combobox2.selecteditem.tostring()+"成绩是:"+score;
}
private void button2_click(object sender, system.eventargs e)
{
get.service1 aa=new ws03.get.service1();
string average=aa.getaverage(combobox1.selecteditem.tostring()).tostring();
label4.text="学生"+combobox1.selecteditem.tostring()+"的平均分是:"+average;
}
private void button3_click(object sender, system.eventargs e)
{
get.service1 aa=new ws03.get.service1();
string order=aa.getorder(combobox1.selecteditem.tostring()).tostring();
label5.text="学生"+combobox1.selecteditem.tostring()+"的排名是:第"+order+"名";
}
然后再用vb.net编写一个asp.net程序来调用该服务:
代码也是非常的简单:
private sub button1_click(byval sender as system.object, byval e as system.eventargs) handles button1.click
dim aa as new [get].service1
label1.text = aa.getscore(dropdownlist1.selecteditem.text, dropdownlist2.selecteditem.text)
end sub
private sub button2_click(byval sender as system.object, byval e as system.eventargs) handles button2.click
dim aa as new [get].service1
label2.text = aa.getaverage(dropdownlist1.selecteditem.text)
end sub
private sub button3_click(byval sender as system.object, byval e as system.eventargs) handles button3.click
dim aa as new [get].service1
label3.text = aa.getorder(dropdownlist1.selecteditem.text)
end sub
当然在这两个程序里都不要忘记添加进该web引用,在本地生成soap代理,只不过有很多的工作都由vs.net这个ide给完成了。
如果是使用webmatrix来编写asp.net消费web服务的话,可就有一番工作需要你自己完成了,这个等下次再讲。