Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

用 Eclipse 建立 Web Service ( Axis2, SOAP 1.2 ) #30

Open
shyangs opened this issue Jun 28, 2019 · 0 comments
Open

用 Eclipse 建立 Web Service ( Axis2, SOAP 1.2 ) #30

shyangs opened this issue Jun 28, 2019 · 0 comments

Comments

@shyangs
Copy link
Owner

shyangs commented Jun 28, 2019

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.

axis2-welcome

STEP 02

設定 Eclipse 的 Preferences / Web Services / Axis2 Preferences/ Axis2 Preferences / Axis2 runtime location 設定為 C:\mylib\axis2-1.7.9
下方出現 Axis2 runtime loaded successfully 表示設定成功.

eclipse_web-services_axis2_preferences_runtime_location

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

Dynamic_Web_Project

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

service_deployment_configuration_web-service_runtime_axis2

STEP 08

用瀏覽器開啟 http://localhost:8080/WsAxis2Demo/services/listServices 會看到我們的 Web Service 資訊
同頁的藍色連結,則是 WSDL

listServices

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.

參考

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant