Eclipse Web Tools Platform (WTP) 提供了圖形化精靈,讓開發者無需手寫 WSDL 即可將普通 Java 類別發布為標準 Web Service。本教學以溫度轉換服務為例,完整演示從專案建立到 SOAP 訊息檢視的全流程。
ConverterProj在 wtp 套件下建立 Converter.java:
package wtp;
public class Converter {
public float celsiusToFarenheit(float celsius) {
return (celsius * 9 / 5) + 32;
}
public float farenheitToCelsius(float farenheit) {
return (farenheit - 32) * 5 / 9;
}
}
關鍵慣例:方法名首字母必須小寫。若使用 CelsiusToFarenheit 會拋出 org.apache.axis.InternalException: Couldn't find a matching Java operation for WSDD operation "celsiusToFarenheit",因 Axis 反射機制僅識別小寫開頭的方法名。
Converter.java → New → Other → Web Services → Web Service
celsiusToFarenheit37,點擊 Invoke98.6
啟用 TCP/IP Monitor 捕獲網路封包:


觀察 SOAP Envelope 結構、命名空間宣告、參數序列化格式,有助於理解 Axis 底層序列化機制與跨平台互通性。
| 問題現象 | 根因 | 解決方案 |
|---|---|---|
| 方法名找不到 | 方法名首字母大寫 | 強制小寫開頭 (camelCase) |
| ClassNotFoundException | 專案未正確部署到 Tomcat | 檢查 Server 標籤頁模組部署狀態 |
| TCP/IP Monitor 無資料 | 監聽埠口衝突 | Window → Preferences → Run/Debug → TCP/IP Monitor 重新配置埠口 |
@WebService、@WebMethod 註解 (JSR-181) 簡化配置wsgen/wsimport 生成客戶端存根本教學源碼及圖片來源:子孑博客 原文連結