使用xfire编写webservice,并通过C#调用

http://tech.ddvip.com   2008年01月18日    社区交流

本文详细介绍使用xfire编写webservice,并通过C#调用

  执行,打印:hello,dennis

  注意,你也可以使用MyEclipse的new webservice client向导自动生成client,同时生成供客户端调用的stub类等。

  最后,我们再编写一个C#调用此web service的例子。

  1.在vs.net中新建一个windows 应用程序项目,并添加一个button,和一个label

使用xfire编写webservice,并通过C#调用

使用xfire编写webservice,并通过C#调用

  2.项目菜单——》添加web应用,输入我们要调用的web服务的wsdl文件的url,并点击前往。

使用xfire编写webservice,并通过C#调用

  3.添加引用之后,vs.net会自动帮你生成提供给客户端调用的stub等,这些文件在名为localhost的命名空间下。此空间下将有一个类,名为HelloWorldService。最后,在button1的onclick事件中添加代码:

usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Text;
usingSystem.Windows.Forms;
namespaceMyProject
{
  publicpartialclassForm1:Form
  {
    localhost.HelloWorldServicehelloService=newlocalhost.HelloWorldService();
    publicForm1()
    {
      InitializeComponent();
    }
    privatevoidbutton1_Click(objectsender,EventArgse)
    {
      label1.Text=helloService.sayHello("dennis");
    }
  }
}

  我们new一个HelloWorldService ,并调用sayHello方法,将结果显示在label上

  4.执行ctr+F5

使用xfire编写webservice,并通过C#调用

使用xfire编写webservice,并通过C#调用

责编:豆豆技术应用

正在加载评论...