这里需要用到的JAR包 :
XmlSchema-1.1.jar
activation-1.1.jar
commons-codec-1.3.jar
commons-httpclient-3.0.jar
commons-logging-1.0.4.jar
jaxb-xjc-2.0.1.jar
jdom-1.0.jar
stax-api-1.0.1.jar
wsdl4j-1.6.1.jar
wstx-asl-3.2.0.jar
xbean-2.2.0.jar
xfire-all-1.2.6.jar
xfire-jsr181-api-1.0-M1.jar
开发环境:
myeclipse 8.5
目录结构:
编写build文件:
<?xml version="1.0" encoding="UTF-8"?>
<!-- ======================================================================
2013-6-18 上午09:30:29 project
description 这个文件作为参照 1-23 行 基本不需要修改
需要修改的仅为 25行的value 27行的value 请根据实际情况修改 Tone
====================================================================== -->
<project name="createClientFile" basedir="."> <!-- 指定lib 路径-->
<property name="lib" value="${basedir}/WebRoot/WEB-INF/lib" />
<!-- 将lib 引入到classpath-->
<path id="myclasspath">
<fileset dir="${lib}">
<include name="*.jar" />
</fileset>
<pathelement location="${createClientFile}" />
</path> <!--指定源文件根目录-->
<property name="code_path" value="${basedir}/src" /> <!--指定webservice地址-->
<property name="wsdl_path" value="http://10.22.7.142:7001/MWWebSite/services/BHDZD_FORFileWebService?wsdl" /> <!--生成文件的存放目录-->
<property name="code_package" value="nariis.pi3000.webservice.client" /> <!--清理-->
<target name="clean" description="清理工作路径">
<!--
<delete dir="${basedir}/src/nariis/pi3000/webservice/client" />
<mkdir dir="${basedir}/src/nariis/pi3000/webservice/client" />
-->
<delete includeEmptyDirs="true">
<fileset dir="${basedir}/src/nariis/pi3000/webservice/client" includes="**/*" defaultexcludes="no" />
</delete>
</target> <!--建立target-->
<target name="createClientFile" description="建立WebService客户端文件">
<taskdef name="getWebService" classname="org.codehaus.xfire.gen.WsGenTask" classpathref="myclasspath" />
<getWebService outputDirectory="${code_path}" wsdl="${wsdl_path}" package="${code_package}" binding="xmlbeans" overwrite="true" />
</target> </project>
运行ant 输出:
Buildfile: D:\Sources\java_myeclipse\XfireClient\build.xml
createClientFile:[getWebService] 2015-4-14 15:48:39 org.codehaus.xfire.gen.Wsdl11Generator generate
[getWebService] 信息: Generating code for WSDL at http://10.22.7.142:7001/MWWebSite/services/BHDZD_FORFileWebService?wsdl with a base URI of http://10.22.7.142:7001/MWWebSite/services/BHDZD_FORFileWebService?wsdl
[getWebService] 2015-4-14 15:48:40 org.codehaus.xfire.gen.jsr181.AbstractServiceGenerator generate
[getWebService] 信息: Creating class nariis.pi3000.webservice.client.BHDZD_FORFileWebServicePortType
[getWebService] 2015-4-14 15:48:40 org.codehaus.xfire.gen.jsr181.AbstractServiceGenerator generate
[getWebService] 信息: Creating class nariis.pi3000.webservice.client.BHDZD_FORFileWebServiceImpl
[getWebService] nariis\pi3000\webservice\client\BHDZD_FORFileWebServiceClient.java
[getWebService] nariis\pi3000\webservice\client\BHDZD_FORFileWebServiceImpl.java
[getWebService] nariis\pi3000\webservice\client\BHDZD_FORFileWebServicePortType.java
BUILD SUCCESSFUL
Total time: 725 milliseconds
测试代码:
package com.client;
import nariis.pi3000.webservice.client.BHDZD_FORFileWebServiceClient;
import nariis.pi3000.webservice.client.BHDZD_FORFileWebServicePortType;public class HelloWordTest {
/**
* @param args*/
public static void main(String[] args) {
// TODO Auto-generated method stub
BHDZD_FORFileWebServiceClient client = new BHDZD_FORFileWebServiceClient();
BHDZD_FORFileWebServicePortType service = client
.getBHDZD_FORFileWebServiceHttpPort();
String result = service.testWebService("側絲测试");
System.out.println(result);
}
}