生成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等。
- 大小: 16.1 KB
分享到:
相关推荐
xfire根据WSDL生成客户端代码.rar
spring+xfire( 编写webservice完整配置+案例)
NULL 博文链接:https://j2ee-yohn.iteye.com/blog/416936
Spring2.5+Hibernate3.0+Xfire1.2.6 实例代码演示文档
xfire客户端生成自动生成java代码调用
xfire webserivce客户端 jar
spring+xfire集成解决方案spring+xfire集成解决方案
外加代码。jar包太大只好截图相送。解决一下问题:1.在网上找到的资料大多是低版本,遇到的问题是读取xml失败 2.网上资料大多是只有spring+xfire 含有Hibernate的少 3.配置时候还遇到spring实现 客户端调用服务器...
XFire中实现WS-Security完整编 Spring+xFire+wss4j配置Helloworld实例 完整说明文档 Myeclipse项目 服务端工程 客户端工程
MyEclipse+xFire开发(收藏)MyEclipse+xFire开发(收藏)
NULL 博文链接:https://zhengdl126.iteye.com/blog/509487
Spring+Hibernate+Xfire+发布WebService教程文档
grails+Xfire webservice
spring +xfire整合 1. xfire + spring 发布webservice 2. 利用 javascript 调用发布的webservice
Spring+xFire实现webService
用MyEclipse+XFire开发Web Services实例,图文并茂,详细记录开发过程。
Spring+xFire+wss4j配置Helloworld完整Demo.rar
spring3.1+xfire1.26 全注解
JQuery1.4.2+Struts2.1.8+JSON0.34+Spring2.5.6+Hibernate3.5+XFire1.2.6整合实例(已上传) 1、JSON0.34使用的是struts2附带的struts2-json-plugin-2.1.8.1.jar 2、db是mysql,名字为test,用户名root,密码空 3、...
Spring+xfire实现WebService