使用Eclipse自带的Axis1插件生成Web Service服务端客户端

it2022-05-09  39

使用Eclipse自带的Axis1插件生成Web Service服务端/客户端
            

JDK版本:1.5.0_22

Eclipse版本:Helios Service Release 2(3.6.2)

WSDL文件的创建过程见http://blog.csdn.net/a19881029/article/details/24625429

创建一个名字为math的Java web工程,并将WSDL文件拷入该工程中

将Axis所需的jar包拷贝至WebRoot\WEB-INF\lib目录下,这些jar包会自动导入math工程中

一,生成Web Service服务端

选中MathImpl.wsdl文件右键->Web Services->Generate Java Bean Skeleton

仅仅生成Web Service服务端代码即可,服务器选择Tomcat 6.0,Web Service环境选择Apache Axis,服务工程选择math工程,选择完成后点击“下一步”:

 然后选择Web Servic服务端代码的生成路径,选择完成后点击“下一步”:

只生成Web Service服务端代码,并不进行部署,这里直接点击“完成”即可

此时可以发现在math工程中自动生成了Web Service服务端的代码和部署/解除文件

只需编写MathImplSoapBindingImpl文件中的服务端具体处理过程即可:

[java] view plain copy print? /**  * MathImplSoapBindingImpl.java  *  * This file was auto-generated from WSDL  * by the Apache Axis 1.4 Apr 22, 2006 (06:55:48 PDT) WSDL2Java emitter.  */    package com.sean.ws;    public class MathImplSoapBindingImpl implements com.sean.ws.MathImpl{      public int plus(int a, int b) throws java.rmi.RemoteException {          //return -3;          int c = a + b;          System.out.println("The result is:" + c);          return c;      }  }   /** * MathImplSoapBindingImpl.java * * This file was auto-generated from WSDL * by the Apache Axis 1.4 Apr 22, 2006 (06:55:48 PDT) WSDL2Java emitter. */ package com.sean.ws; public class MathImplSoapBindingImpl implements com.sean.ws.MathImpl{ public int plus(int a, int b) throws java.rmi.RemoteException { //return -3; int c = a + b; System.out.println("The result is:" + c); return c; } }

 

二,生成Web Service客户端

选中MathImpl.wsdl文件右键->Web Services->Generate Client

 只生成Web Service客户端代码,选择完成后点击“下一步”:

然后选择Web Servic客户端代码的生成路径,选择完成后点击“完成”:

此时可以发现在math工程中自动生成了Web Service客户端代码

直接使用MathImplProxy类即可:

[java] view plain copy print? package com.sean.ws;    import java.rmi.RemoteException;    public class Test {      public static void main(String[] args) throws RemoteException {          MathImplProxy proxy = new MathImplProxy();          proxy.plus(1, 2);      }  }   package com.sean.ws; import java.rmi.RemoteException; public class Test { public static void main(String[] args) throws RemoteException { MathImplProxy proxy = new MathImplProxy(); proxy.plus(1, 2); } }

 

转载于:https://www.cnblogs.com/mengen/p/9056455.html

相关资源:数据结构—成绩单生成器

最新回复(0)