Java6开发WebService应用—生成服务端(一)
Java6开发WebService应用—生成服务端(1)
之前常常用CXF、Axis2、XFire等来开发结合Java语言来开发Web Service应用,这样的好处是用途广,灵活,另外一个重要原因是我们的生产环境是Java5。
但实际上Java6中已经支持用Java开发WebService应用了,而且很方便。这样就大大减少了项目安装部署的代价,因为选择开源的框架依赖大量第三方包,程序的尺寸倍增。
下面是一个Java6开发Web Service的入门例子。(JDK1.6环境下支持)
package java_soa; import javax.jws.WebService; import javax.xml.ws.Endpoint; @WebService public class Java6WebService { /** * Java6开发WebService测试 * wangzp 2014-10-17 */ public String doSomething(){ return "java6 WebService 调试通过了!"; } /** * @param args */ public static void main(String[] args) { //发布地址 Endpoint.publish("http://192.168.8.121:8099/java6ws/java_soa.Java6WebService", new Java6WebService()); } }
运行后,在浏览器中访问http://192.168.8.121:8099/java6ws/java_soa.Java6WebService?wsdl会得到wsdl 如下:

wsdl显示正常后,说明程序调试正常了。
wsdl显示正常后,说明程序调试正常了。
(补充):1. myeclipse8.5运行界面。

2. 程序报错,后由jdk1.6调整为jdk1.7后正常。
2. 程序报错,后由jdk1.6调整为jdk1.7后正常。
at com.sun.xml.internal.ws.transport.http.server.HttpEndpoint.publish(HttpEndpoint.java:269)
at com.sun.xml.internal.ws.transport.http.server.EndpointImpl.publish(EndpointImpl.java:87)
at com.sun.xml.internal.ws.spi.ProviderImpl.createAndPublishEndpoint(ProviderImpl.java:59)
at javax.xml.ws.Endpoint.publish(Endpoint.java:156)
at com.enic.service.Java6WebService.main(Java6WebService.java:14)
Caused by: class: com.enic.service.jaxws.DoSomething could not be found
at com.sun.xml.internal.ws.modeler.RuntimeModeler.getClass(RuntimeModeler.java:271)
at com.sun.xml.internal.ws.modeler.RuntimeModeler.processDocWrappedMethod(RuntimeModeler.java:562)
at com.sun.xml.internal.ws.modeler.RuntimeModeler.processMethod(RuntimeModeler.java:509)
at com.sun.xml.internal.ws.modeler.RuntimeModeler.processClass(RuntimeModeler.java:355)
at com.sun.xml.internal.ws.modeler.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:251)
at com.sun.xml.internal.ws.server.RuntimeEndpointInfo.createSEIModel(RuntimeEndpointInfo.java:170)
at com.sun.xml.internal.ws.server.RuntimeEndpointInfo.init(RuntimeEndpointInfo.java:317)
at com.sun.xml.internal.ws.transport.http.server.HttpEndpoint.publish(HttpEndpoint.java:298)
at com.sun.xml.internal.ws.transport.http.server.HttpEndpoint.publish(HttpEndpoint.java:263)
... 4 more