概述
这里提供一个最简单的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内嵌的浏览器,或者其他外部的浏览器。

我这里使用了谷歌浏览器,后来发现无法看到SOAP报文,又切换了IE浏览器。
2. 打开工具
Run - Launch the Web Services Explorer

3. 请求服务

这里的wsdl的地址,是我们在服务端发布的地址,加上
?wsdl
。


