参考书: [ 基于Apache CXF构建SOA应用]
wsdl2java -frontend jaxws21 -p com.test -d src -ant -encoding utf-8 -client MobileCodeWS.wsdl
com/test/CXFClient.java
package com.test;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import com.test.MobileCodeWSSoap;
public class CXFClient {
public CXFClient() {
}
public static void main(String[] args) {
if (args.length != 1){
System.out.println(" usage: java -cp ws.jar;bin com.test.CXFClient MobileCode ");
return;
}
if (args[0] == null || "".equals(args[0])) return;
// 定义JaxWs的代理工厂
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
// 设置JaxWs代理工厂的属性,包括服务类和地址
factory.setServiceClass(MobileCodeWSSoap.class);
factory.setAddress("http://www.webxml.com.cn/WebServices/MobileCodeWS.asmx");
// 获取服务类的对象并处理
MobileCodeWSSoap ms = (MobileCodeWSSoap) factory.create();
String result = ms.getMobileCodeInfo(args[0],"");
if ( result != null){
System.out.println("result:" + result);
} else {
System.out.println("result is null.");
}
}
}
在 build.xml 中增加
<target name="CXFClient" description="Run com.test.CXFClient" depends="compile">
<property name="param" value=""/>
<cxfrun classname="com.test.CXFClient"
param1="手机号码"/>
</target>
执行 ant -verbose CXFClient