XFire根据WSDL生成客户端程序

XFire根据WSDL生成客户端程序

 

1.更新The XFire Eclipse plugin

The XFire Eclipse plugin provides Eclipse support for XFire's WSDL->Code generator. It requires Eclipse 3.2 and Java 5.

Installing the Plugin

To install the Eclipse XFire plugin:

go to the Help menu, select "Software Updates" and then select "Find and Install."

Select "Search for new features to install" and click Next.

Select "Create New Remote Site" and enter "XFire" as the name and http://dist.codehaus.org/xfire/update/ as the eclipse update site.

Select OK.

Select Finish

 

2.安装好后出现

 

3.新建一个web project,将

 

 

 

生成的client程序放到源文件夹中,

不要加myeclipse中的XFire库文件,因为客户端运行所导入的xfire 1.2.6 和服务器端的xfire1.2.5版本不一致,导致以上问题。

直接下载xfire- 1.2.6 ,把其中的lib加到project就好了。

4.最后写个测试程序就好。

import com.kuaff.xfire.samples.MathServiceClient;

import com.kuaff.xfire.samples.MathServicePortType;

 

public class Test {

    public static void main(String[] args) {

       MathServiceClient client = new MathServiceClient();

       MathServicePortType MathService = client.getMathServiceHttpPort();

       // 调用服务

       long result = MathService.add(1, 2);

       System.out.println("结果:" + result);

    }

}

 

当有参数传递时,

import test.HelloServiceClient;

import test.HelloServicePortType;

import test.ObjectFactory;

import test.User;

import javax.xml.namespace.QName;

 

 

 

 

public class TestAddress {

    public static void main(String[] args) {

       HelloServiceClient client = new HelloServiceClient();

       HelloServicePortType HelloService = client.getHelloServiceHttpPort();

      

//     当要传递参数时,调用ObjectFactory中的公用方法,而不用自己还要

       //new JAXBElement<String>(new

//     QName("http://test", "username"),String.class,"dfdfs");

       //直接调用factory.createUserUsername("dfdfs")返回JAXBElement<String>类型

      

       ObjectFactory  factory=new ObjectFactory();

       User user=factory.createUser();

       user.setPassword(factory.createUserPassword("afdsafsd"));

       user.setUsername(factory.createUserUsername("dfdfs"));

      

       // 调用服务

       //JAXBElement转化为String,调用getValue();

       System.out.println(HelloService.getUser(user).getUsername().getValue());

    }

}

 
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值