`
ioriyagami808
  • 浏览: 28078 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

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代码:
<project name="XFire-WsGen" basedir="./WsGen" default="wsgen">
	<path id="maven.compile.classpath">
		<fileset file="${basedir}/lib/*.jar"/>
	</path>
	<!-- Remove classes directory for clean build -->
	<target name="clean" description="Prepare for clean build">
		<delete dir="${basedir}/client"/>
		<mkdir dir="${basedir}/client"/>
	</target>
	<target name="wsgen" depends="clean">
		<taskdef name="WsGenTask" classname="org.codehaus.xfire.gen.WsGenTask" classpathref="maven.compile.classpath"/>
		<WsGenTask outputDirectory="${basedir}/client" wsdl="http://localhost:8080/mytest/services/HelloWordService?wsdl" package="com.tongtech.webservice.client" overwrite="true"/>
	</target>
</project>


需要修改WSDL的地址,另外,package为客户端生成后所在包的包名
执行ant打包即可生成,生成后可考到eclipse下运行调试
分享到:
评论
5 楼 ennaanne 2012-05-22  

GeoIPServiceClient service = new GeoIPServiceClient();
        GeoIPServiceSoap geoIPClient = service.getGeoIPServiceSoap("http://localhost/xfire/services/GeoIPService?wsdl");

这里不要带 wsdl ,
4 楼 ennaanne 2012-05-22  
dvdvd
3 楼 dreamer_0924 2007-11-21  
在为webservice产生客户端代码时,产生的客户端代码的domain类总是和和原有类冲突,怎么办啊?能不能设置产生的客户端代码domain类包名?
2 楼 ioriyagami808 2007-08-27  
客户端访问代码不正确,新建一个clientTest.java
调用ANT生成的Client类
并通过该对象获得一个HttpPort
然后用这个对象来获得你封装的WebService方法
1 楼 match927 2007-08-20  
请教下:生成xfire客户端后测试时出现了错误:
xception in thread "main" org.codehaus.xfire.XFireRuntimeException: Could not invoke service.. Nested exception is org.codehaus.xfire.fault.XFireFault: There must be a method name element.
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());
}

相关推荐

Global site tag (gtag.js) - Google Analytics