Ant+xFire生成客户端代码实战

生成xfire客户端有多种方式,直接调用xFire暴露的接口、使用xfire eclipse ide生成客户端代码、用ant调用org.codehaus.xfire.gen.WsGenTask声称代码。这里主要讲用ant生成代码的方式。

 

1、新建一个web项目,导入xFire需要的软件包;

 

2、在Web-Root下创建build.xml、build.properties,内容分别为:

WebRoot/build.xml

<project name="WebService" basedir="." default="gen-webservice">
	<property file="build.properties">
	</property>

	<!--定义类路径-->
	<path id="project-classpath">
		<fileset dir="./WEB-INF/lib">
			<!--表示包括lib.dir目录以及子目录的所有的jar文件-->
			<include name="**/*.jar">
			</include>
		</fileset>
	</path>

	<target name="gen-webservice">
		<taskdef name="wsgen" classname="org.codehaus.xfire.gen.WsGenTask" classpathref="project-classpath" />

		<wsgen outputDirectory="${src.dir}" wsdl="${wsdl.dir}" package="client" overwrite="true" />
	</target>
</project>
 

WebRoot/build.properties

src.dir=${basedir}/src
lib.dir=${basedir}/lib
wsdl.dir=http\://localhost\:8080/xFire/testService.ws?wsdl

 

 

3、运行ant,生成客户端代码。

代码结构如下图

 

注意红色部分。

 

4、具体调用代码:

Test.java

package test;

import client.IHelloClient;
import client.IHelloPortType;

public class Test2 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		IHelloClient hlo = new IHelloClient();
		IHelloPortType helloType = hlo.getIHelloHttpPort();
		String rtn = helloType.helloTo("张山");
		System.out.println("rtn is " + rtn);
		
		rtn = helloType.hello();
		System.out.println("rtn2 is " + rtn);
		
	}

}

 运行结果:

rtn is hello 张山!
rtn2 is hello

 

调用成功!

 

 

此种办法不用关心url、接口等,一般情况下,只需要调用指定方法、传递参数就可以调用远程服务。

 

另一种方法:使用soap UI 工具生成,可以选择支持xfire、axis等。

 

 

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值