webservice系列教学(6)-如何调用webservice(C#,)
2024-07-21 02:27:40
供稿:网友
4. 5使用c#调用
无需下载任何组件
新建项目visual c#项目windows应用程序。
在解决方案资源管理器中添加web引用,输入wsdl文件所在地址。
将web引用改名.
yundan.(service_name)即可引用
*需引用system.web.services*
例程:
using system;
using system.drawing;
using system.collections;
using system.componentmodel;
using system.windows.forms;
using system.data;
namespace csharp
{
public class form1 : system.windows.forms.form
{
private system.windows.forms.label label1;
private system.windows.forms.textbox textbox1;
private system.componentmodel.container components = null;
public form1()
{
initializecomponent();
}
protected override void dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.dispose();
}
}
base.dispose( disposing );
}
#region windows form designer generated code
private void initializecomponent()
{
this.label1 = new system.windows.forms.label();
this.textbox1 = new system.windows.forms.textbox();
this.suspendlayout();
this.label1.autosize = true;
this.label1.location = new system.drawing.point(88, 48);
this.label1.name = "label1";
this.label1.size = new system.drawing.size(91, 14);
this.label1.tabindex = 0;
this.label1.text = "webservice演示";
this.textbox1.location = new system.drawing.point(88, 128);
this.textbox1.name = "textbox1";
this.textbox1.tabindex = 1;
this.textbox1.text = "textbox1";
this.autoscalebasesize = new system.drawing.size(6, 14);
this.clientsize = new system.drawing.size(292, 273);
this.controls.addrange(new system.windows.forms.control[]
{
this.textbox1,
this.label1
});
this.name = "form1";
this.text = "c#webservie演示";
this.load += new system.eventhandler(this.form1_load);
this.resumelayout(false);
}
#endregion
[stathread]
static void main()
{
application.run(new form1());
}
private void form1_load(object sender, system.eventargs e)
{
int str;
你的web引用的名字.service1 cc=new 你的web引用的名字.service1();
str=cc.test(123,324);
textbox1.text=str.tostring();
}
}
}