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 /** * 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 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); } }