Ant脚本发布XFire WebService 客户端
可以不使用XFire的eclipse插件,直接使用ANT脚本,和XFire1.2.6的jar包即可生成WebService客户端
目录结构为:
build.xml
WsGen的文件夹(此处文件夹名随意,ant脚本中对应该文件夹名即可)
WsGen下建立client,lib文件夹,lib下置放xFire1.2.6所有jar包
Build.xml代码:
需要修改WSDL的地址,另外,package为客户端生成后所在包的包名
执行ant打包即可生成,生成后可考到eclipse下运行调试org.codehaus.xfire.fault.XFireFault: There must be a method name element.
at org.codehaus.xfire.service.binding.WrappedBinding.readMessage(WrappedBinding.java:32)
at org.codehaus.xfire.soap.handler.SoapBodyHandler.invoke(SoapBodyHandler.java:42)
at org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)
at org.codehaus.xfire.client.Client.onReceive(Client.java:406)
at org.codehaus.xfire.transport.http.HttpChannel.sendViaClient(HttpChannel.java:139)
at org.codehaus.xfire.transport.http.HttpChannel.send(HttpChannel.java:48)
at org.codehaus.xfire.handler.OutMessageSender.invoke(OutMessageSender.java:26)
at org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)
at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:79)
at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:114)
at org.codehaus.xfire.client.Client.invoke(Client.java:336)
at org.codehaus.xfire.client.XFireProxy.handleRequest(XFireProxy.java:77)
at org.codehaus.xfire.client.XFireProxy.invoke(XFireProxy.java:57)
at $Proxy12.getGeoIP(Unknown Source)
at com.webservice.client.Client.main(Client.java:22)
测试代码:
public static void main(String[]ags) throws MalformedURLException
{
GeoIPServiceClient service = new GeoIPServiceClient();
GeoIPServiceSoap geoIPClient = service.getGeoIPServiceSoap("http://localhost/xfire/services/GeoIPService?wsdl");
System.out.println("The country is: " +
geoIPClient.getGeoIP("216.73.126.120").getCountryName());
} 2 楼 ioriyagami808 2007-08-27 客户端访问代码不正确,新建一个clientTest.java
调用ANT生成的Client类
并通过该对象获得一个HttpPort
然后用这个对象来获得你封装的WebService方法 3 楼 dreamer_0924 2007-11-21 在为webservice产生客户端代码时,产生的客户端代码的domain类总是和和原有类冲突,怎么办啊?能不能设置产生的客户端代码domain类包名? 4 楼 ennaanne 2012-05-22 dvdvd 5 楼 ennaanne 2012-05-22
GeoIPServiceClient service = new GeoIPServiceClient();
GeoIPServiceSoap geoIPClient = service.getGeoIPServiceSoap("http://localhost/xfire/services/GeoIPService?wsdl");
这里不要带 wsdl ,