這裡提供一個最簡單的Web Service的實現,基於JAX-WS。除了jdk不需要任何其他jar包,使用Eclipse提供的Web Services Explorer訪問服務。
概述
這裡提供一個最簡單的Web Service的實現,基於JAX-WS。除了jdk不需要任何其他jar包,使用Eclipse提供的Web Services Explorer訪問服務。
服務端的實現
package cn.ljl.sand.jws.chapter0.service; import javax.jws.WebService; import javax.xml.ws.Endpoint; @WebService public class HelloService { public String hello(String name) { return "Hello," + name; } public static void main(String[] args) { String address = "http://localhost:6666/service/hello"; Endpoint.publish(address, new HelloService()); } }
這裡類有兩個地方值得註意:
- WebService註解
這個註解將這個類聲明為Web Service - main方法
使用Endpoint的publish方法發佈服務
通過Eclipse的工具進行訪問
Eclipse內嵌了Web Services Explorer工具,可以作為客戶端,訪問我們上面發佈的服務。
1. 在Eclipse設置web瀏覽器
Web Services Explorer需要使用瀏覽器打開,可以使用Eclipse內嵌的瀏覽器,或者其他外部的瀏覽器。
2. 打開工具
Run - Launch the Web Services Explorer
3. 請求服務

?wsdl
。



