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

使用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文件中的服务端具体处理过程即可:

  1. /** 
  2.  * MathImplSoapBindingImpl.java 
  3.  * 
  4.  * This file was auto-generated from WSDL 
  5.  * by the Apache Axis 1.4 Apr 22, 2006 (06:55:48 PDT) WSDL2Java emitter. 
  6.  */  
  7.   
  8. package com.sean.ws;  
  9.   
  10. public class MathImplSoapBindingImpl implements com.sean.ws.MathImpl{  
  11.     public int plus(int a, int b) throws java.rmi.RemoteException {  
  12.         //return -3;  
  13.         int c = a + b;  
  14.         System.out.println("The result is:" + c);  
  15.         return c;  
  16.     }  
  17. }  
/**
 * 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类即可:

  1. package com.sean.ws;  
  2.   
  3. import java.rmi.RemoteException;  
  4.   
  5. public class Test {  
  6.     public static void main(String[] args) throws RemoteException {  
  7.         MathImplProxy proxy = new MathImplProxy();  
  8.         proxy.plus(1, 2);  
  9.     }  
  10. }  
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);
	}
}

猜你喜欢

转载自www.cnblogs.com/mengen/p/9056455.html