You are on page 1of 10

AXIS 安裝與 Web Service 發佈 編輯者:陳志華

AXIS 安裝與 Web Service 發佈

一、AXIS2 安裝
(1) 下載 AXIS2,http://ws.apache.org/axis2/download/1_3/download.cgi

(2) 解壓縮 axis2.war 到% CATALINA_HOME% \ webapps \ axis2.war

(3) 重新啟動 Tomcat

二、Code Generator Wizard - Eclipse 外掛安裝


(1) 下載 Eclipse 外掛,http://apache.ntu.edu.tw/ws/axis2/tools/1_3/

(2) axis2-eclipse-codegen-wizard.zip 解壓縮到 Eclipse \ plugins 目錄中

第1頁
AXIS 安裝與 Web Service 發佈 編輯者:陳志華

三、發佈 Web Service


(1) 開啟 Eclipse,並新增 Java Project,命名為 HelloWorldService

(2) 於專案中新增 HelloWorldService.java

(3) 輸入程式碼,以下為加法範例
public class HelloWorldService {
public int echo(int a1, int a2) {
int value = a1 + a2;
System.out.println("Service HelloWorldService: " + value);
return value;
}
}

(4) 新增目錄 META-INF 於 HelloWorldService

第2頁
AXIS 安裝與 Web Service 發佈 編輯者:陳志華

(5) 新增 services.xml 檔案於\ META-INF \目錄下


其中 services.xml 內容為
<service>
<parameter name="ServiceClass" locked="false">
HelloWorldService
</parameter>
<operation name="echo">
<messageReceiver
class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
</operation>
</service>

第3頁
AXIS 安裝與 Web Service 發佈 編輯者:陳志華

(6) 封裝成 aar 檔


選擇「File \ Export\」

選擇 JAR file

第4頁
AXIS 安裝與 Web Service 發佈 編輯者:陳志華

取消選取右邊的.classpath、.project,並設定好輸出路徑,完成後按 Finish

(7) 部署 HelloWorldService.aar,網址:http://127.0.0.1:8080/axis2/axis2-admin/
帳號:admin,密碼:axis2

第5頁
AXIS 安裝與 Web Service 發佈 編輯者:陳志華

(8) 點選左方之「Upload Service」


,並在 Service archive 選擇置入剛才的 aar 檔案,
並點選 Upload

(9) 點選左方之「Available Services」,檢查服務是否部署成功

(10) 下 載 WSDL 檔 , 於 該 服 務 使 用 滑 鼠 右 鍵 儲 存 該 檔 案 , 並 放 置 於
HelloWorldService 專案下

第6頁
AXIS 安裝與 Web Service 發佈 編輯者:陳志華

四、取得 Web Service


(1) 開啟 Eclipse,並新增 Java Project,命名為 HelloWorldService

(2) 設定專案屬性,於專案點選滑鼠右鍵,選擇 Properties,並點選「Java Build Path


,加入% CATALINA_HOME% \ webapps \ axis2 \ WEB-INF \ lib 裡的
\ Libraries」
jar 檔案

(3) 點選「File \ New \ Other…」,選擇 Axis2 Code Generator

第7頁
AXIS 安裝與 Web Service 發佈 編輯者:陳志華

選擇 Generate Java source code from a WSDL file

選擇剛才儲存 WSDL 的路徑

第8頁
AXIS 安裝與 Web Service 發佈 編輯者:陳志華

設定輸出的檔案為 HelloWorldClient 專案路徑,完成後重新整理專案<F5>鍵

第9頁
AXIS 安裝與 Web Service 發佈 編輯者:陳志華

(4) 新增 HelloWorldClient.java,並輸入程式碼
import org.apache.ws.axis2.HelloWorldServiceStub;
import org.apache.ws.axis2.HelloWorldServiceStub.EchoResponse;

public class HelloWorldClient {


public static void main(String[] args) throws Exception {
HelloWorldServiceStub stub = new HelloWorldServiceStub();
HelloWorldServiceStub.Echo request = new
HelloWorldServiceStub.Echo();
request.setA1(1);
request.setA2(2);
EchoResponse response = stub.echo(request);
System.out.println("Response : " + response.get_return());
}
}

(5) 程式執行結果

第 10 頁

You might also like