XFire的Web Servicep客户端快速配置

一、把XFire及其需要的包都拷过来

下载的XFire包,及其解压后,lib目录下全部的包都拷过来

在项目的根目录下建立一个ant文件(BUILD.XML),必须指出lib目录所在的路径和服务器端的wsdl路径:

xml 代码
  1. <project name="struts-hibernate-eg" basedir="." default="help">  
  2.     
  3.     <path id="build.classpath">  
  4.         <fileset file="lib/*.jar" />  
  5.     </path>  
  6.   
  7.  <!-- Help -->  
  8.  <target name="help">  
  9.   <echo message="BASEDIR:${basedir}"/>  
  10.   <echo message="targer: help"/>  
  11.   <echo message="usage: ant "/>  
  12.  </target>  
  13.     
  14.  <!-- Wsgen -->  
  15.     <target name="Wsgen">  
  16.      <taskdef name="wsgen" classname="org.codehaus.xfire.gen.WsGenTask" classpathref="build.classpath" />  
  17.      <wsgen outputDirectory="bin" wsdl="http://192.168.0.16:8080/MathService/services/MathService?wsdl" package="client" />  
  18.     </target>  
  19.     
  20. </project>  

二、运行通过ant运行这个文件,即通过服务器的wsdl类热核,生成客户端所需要的类

其中MathServiceClient.java和MathServicePortType.java,这两个类是最重要的,其他的可要可不要

三、编写自己的类,调用客户端类,即可以远程访问Web Service,并调用其对应的类

java 代码
  1. public class TestClient {   
  2.   
  3.  public static void main(String[] args) {   
  4.   
  5.   MathServiceClient msc=new MathServiceClient();   
  6.   MathServicePortType msp=msc.getMathServiceHttpPort();   
  7.   System.out.println(msp.add(100200));   
  8.   System.out.println(msp.sub(100200));   
  9.  }   
  10.   
  11. }   

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值