XFire根据WSDL生成客户端程序

XFire根据WSDL生成客户端程序<o:p></o:p>

<o:p> </o:p>

1.更新The XFire Eclipse plugin<o:p></o:p>

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

Installing the Plugin<o:p></o:p>

To install the Eclipse XFire plugin:<o:p></o:p>

go to the Help menu, select "Software Updates" and then select "Find and Install." <o:p></o:p>

Select "Search for new features to install" and click Next. <o:p></o:p>

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

Select OK. <o:p></o:p>

Select Finish <o:p></o:p>

<o:p> </o:p>

2.安装好后出现

<o:p></o:p>

<v:shapetype id="_x0000_t75" stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" o:preferrelative="t" o:spt="75" coordsize="21600,21600"><v:stroke joinstyle="miter"></v:stroke><v:formulas><v:f eqn="if lineDrawn pixelLineWidth 0"></v:f><v:f eqn="sum @0 1 0"></v:f><v:f eqn="sum 0 0 @1"></v:f><v:f eqn="prod @2 1 2"></v:f><v:f eqn="prod @3 21600 pixelWidth"></v:f><v:f eqn="prod @3 21600 pixelHeight"></v:f><v:f eqn="sum @0 0 1"></v:f><v:f eqn="prod @6 1 2"></v:f><v:f eqn="prod @7 21600 pixelWidth"></v:f><v:f eqn="sum @8 21600 0"></v:f><v:f eqn="prod @7 21600 pixelHeight"></v:f><v:f eqn="sum @10 21600 0"></v:f></v:formulas><v:path o:connecttype="rect" gradientshapeok="t" o:extrusionok="f"></v:path><o:lock aspectratio="t" v:ext="edit"></o:lock></v:shapetype><v:shape id="_x0000_i1025" style="WIDTH: 388.5pt; HEIGHT: 362.25pt" type="#_x0000_t75"><v:imagedata o:title="ScreenShot045" src="file:///C:\DOCUME~1\pengch\LOCALS~1\Temp\msohtml1\01\clip_image001.png"></v:imagedata></v:shape><o:p></o:p>

<o:p> </o:p>

3.新建一个web project,将<o:p></o:p>

<o:p> </o:p>

<o:p> </o:p>

<o:p> </o:p>

生成的client程序放到源文件夹中,<o:p></o:p>

不要加myeclipse中的XFire库文件,因为客户端运行所导入的xfire<st1:chsdate w:st="on" isrocdate="False" islunardate="False" day="30" month="12" year="1899">1.2.6</st1:chsdate>和服务器端的xfire1.2.5版本不一致,导致以上问题。<o:p></o:p>

直接下载xfire-<st1:chsdate w:st="on" isrocdate="False" islunardate="False" day="30" month="12" year="1899">1.2.6</st1:chsdate>,把其中的lib加到project就好了。<o:p></o:p>

<v:shape id="_x0000_i1026" style="WIDTH: 3in; HEIGHT: 221.25pt" type="#_x0000_t75"><v:imagedata o:title="ScreenShot046" src="file:///C:\DOCUME~1\pengch\LOCALS~1\Temp\msohtml1\01\clip_image003.png"></v:imagedata></v:shape><o:p></o:p>

4.最后写个测试程序就好。<o:p></o:p>

import com.kuaff.xfire.samples.MathServiceClient;<o:p></o:p>

import com.kuaff.xfire.samples.MathServicePortType;<o:p></o:p>

<o:p> </o:p>

public class Test {<o:p></o:p>

    public static void main(String[] args) {<o:p></o:p>

       MathServiceClient client = new MathServiceClient();<o:p></o:p>

       MathServicePortType MathService = client.getMathServiceHttpPort();<o:p></o:p>

       // 调用服务<o:p></o:p>

       long result = MathService.add(1, 2);<o:p></o:p>

       System.out.println("结果:" + result);<o:p></o:p>

    }<o:p></o:p>

}<o:p></o:p>

<o:p> </o:p>

当有参数传递时,<o:p></o:p>

import test.HelloServiceClient;<o:p></o:p>

import test.HelloServicePortType;<o:p></o:p>

import test.ObjectFactory;<o:p></o:p>

import test.User;<o:p></o:p>

import javax.xml.namespace.QName;<o:p></o:p>

<o:p> </o:p>

<o:p> </o:p>

<o:p> </o:p>

<o:p> </o:p>

public class TestAddress {<o:p></o:p>

    public static void main(String[] args) {<o:p></o:p>

       HelloServiceClient client = new HelloServiceClient();<o:p></o:p>

       HelloServicePortType HelloService = client.getHelloServiceHttpPort();<o:p></o:p>

       <o:p></o:p>

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

       //new JAXBElement<String>(new<o:p></o:p>

//     QName("http://test", "username"),String.class,"dfdfs"); <o:p></o:p>

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

       <o:p></o:p>

       ObjectFactory  factory=new ObjectFactory();<o:p></o:p>

       User user=factory.createUser();<o:p></o:p>

       user.setPassword(factory.createUserPassword("afdsafsd"));<o:p></o:p>

       user.setUsername(factory.createUserUsername("dfdfs"));<o:p></o:p>

       <o:p></o:p>

       // 调用服务<o:p></o:p>

       //JAXBElement转化为String,调用getValue();<o:p></o:p>

       System.out.println(HelloService.getUser(user).getUsername().getValue());<o:p></o:p>

    }<o:p></o:p>

}<o:p></o:p>

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值