WSDL生成Web Service java客户端

[quote]最近做系统间数据导入导出时需要用到web service,所以需要通过wsdl生成java客户端来读取数据。[/quote]

[b]方法一: 使用xfire eclipse plugin生成java客户端[/b]

1 安装xfire eclipse plugin,update site:
http://dist.codehaus.org/xfire/update/

2 新建java project: WSTest. 我们用一个免费的web service服务做测试。 这是个手机号码归属地查询的wsdl
[quote][url]http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl[/url][/quote]
3 File->New->Other ,选择XFire文件夹下的Code generation from WSDL document,打开代码生成向导
[img]http://dl.iteye.com/upload/attachment/337212/86717438-7bb9-3e5d-a895-9ae4d04b1465.jpg[/img]

4 点next,填入上面的wsdl地址,生成的java目录,包名。
[img]http://dl.iteye.com/upload/attachment/337214/475c3ae5-ca97-3420-b908-fc4008e295af.jpg[/img]

5 右击WSTest->properties->Xfire,把xfire所有的java包勾上。
[img]http://dl.iteye.com/upload/attachment/337218/4c76690d-3e64-3f09-9d9f-fa751ecf6ac2.jpg[/img]

6 新建一个带main函数的class,
import com.wilson.MobileCodeWSClient;
public class Main {
public static void main(String[] args) {
MobileCodeWSClient client = new MobileCodeWSClient();
System.out.println(client.getMobileCodeWSSoap().getMobileCodeInfo("15801902188", null));
}
}



[b]方法二: ant生成xfire web service java client[/b]
[quote]我们同样可以用一个ant脚本生成java 客户端,拷贝所有xfire jar到lib目录下。[/quote]
<project name="XFire-WsGen" basedir="./WsGen" default="wsgen">
<path id="maven.compile.classpath">
<fileset file="${basedir}/lib/*.jar"/>
</path>
<!-- Remove classes directory for clean build -->
<target name="clean" description="Prepare for clean build">
<delete dir="${basedir}/client"/>
<mkdir dir="${basedir}/client"/>
</target>
<target name="wsgen" depends="clean">
<taskdef name="WsGenTask" classname="org.codehaus.xfire.gen.WsGenTask" classpathref="maven.compile.classpath"/>
<WsGenTask outputDirectory="${basedir}/client" wsdl="http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl" package="com.wilson" overwrite="true"/>
</target>
</project>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值