Description
STEP 00
使用的工具/環境:
- windows10
- jdk1.8.0_141
- Eclipse Jee 2018-12
- Tomcat 9.0.21
- axis2-1.7.9
- (WAR distribution) axis2-1.7.9-war.zip 解壓, 得到 axis2.war
- (Binary distribution) axis2-1.7.9-bin.zip 解壓到 C:\mylib\axis2-1.7.9 (或你喜歡的位置)
STEP 01
Tomcat 我下載的是 apache-tomcat-9.0.21.zip, 這是免安裝版, 把下載的 axis2.war 放到 apache-tomcat-9.0.21\webapps 目錄下, 執行 apache-tomcat-9.0.21\bin\startup.bat
開啟瀏覽器, 輸入 http://localhost:8080/axis2/ , 如果出現了Axis2的 welcome 頁, 表示Axis2成功安裝到Tomcat裡了.
執行 apache-tomcat-9.0.21\bin\shutdown.bat 關掉 Tomcat.
STEP 02
設定 Eclipse 的 Preferences / Web Services / Axis2 Preferences/ Axis2 Preferences / Axis2 runtime location 設定為 C:\mylib\axis2-1.7.9
下方出現 Axis2 runtime loaded successfully 表示設定成功.
STEP 03
Eclipse 設定 Server 使用 tomcat-9.0.21
STEP 04
Eclipse 裡新增一個 Dynamic Web Project.
- Project name 填 WsAxis2Demo
- Target runtime 填 Apache Tomcat v9
- Dynamic Web Module Version 填 2.5 (ref: stackoverflow#4674363)
- 點 Configuration 右側的 Modify.. 在新出現的Project Facets視窗裡, 勾選 Axis2 Web Services, 按OK 在原來的視窗按 Finish
STEP 05
JSTL
如果這時候 Eclipse 報錯 Can not find the tag library descriptor for "http://java.sun.com/jsp/jstl/core"
把 jstl-1.2.jar 放到專案的 /WEB-INF/lib/
裡 (ref: stackoverflow#13285826)
XmlSchema Core
把 xmlschema-core-2.2.4.jar 放到專案的 /WEB-INF/lib/
裡 (ref: stackoverflow#35188087)
STEP 06
建一個class
package io.github.shyangs;
public class MyWs {
public int addTwoNumbers(int firstNumber, int secondNumber) {
return firstNumber + secondNumber;
}
}
STEP 07
- MyWs.java 上右鍵選 Web Services / Create Web Service
- 點 Configuration 下方的 Server runtime 連結
- Web Service runtime 選擇 Axis2
- 一路 Next 後, 啟動 Server
STEP 08
用瀏覽器開啟 http://localhost:8080/WsAxis2Demo/services/listServices 會看到我們的 Web Service 資訊
同頁的藍色連結,則是 WSDL
STEP 09
修改 services.xml 裡的 messageReceiver mep屬性值
從
<service name="MyWs" >
<Description>
Please Type your service description here
</Description>
<messageReceivers>
<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only" class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />
<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out" class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
</messageReceivers>
<parameter name="ServiceClass" locked="false">io.github.shyangs.MyWs</parameter>
</service>
改為
<service name="MyWs" >
<Description>
Please Type your service description here
</Description>
<messageReceivers>
<messageReceiver mep="http://www.w3.org/ns/wsdl/in-only" class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />
<messageReceiver mep="http://www.w3.org/ns/wsdl/in-out" class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
</messageReceivers>
<parameter name="ServiceClass" locked="false">io.github.shyangs.MyWs</parameter>
</service>
否則Client呼叫時, 會叫不到Service, 報出錯誤 The ServiceClass object does not implement the required method in the following form: OMElement xxxxx(OMElement e)
(ref: stackoverflow#36319901)
改完要重啟 Server.