使用java6做webservice

做webservice,大家可能立马想到axis、xfire等框架,素不知java6有内置的webservice服务器,几行就可以搞定一个webservice呢?

代码如下:

package com.geostar.geoglobe.jaxws;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.ParameterStyle;
import javax.xml.ws.Endpoint;
@SOAPBinding(parameterStyle=ParameterStyle.BARE)
@WebService(serviceName="GeoGlobeServer" ,targetNamespace="http://www.geostar.com.cn")
public class WSDemo { 
 @WebMethod
 @WebResult(name="doSomethingResponse")
 public  String  doSomething(@WebParam(name="input")String input){
  return  "hello:"+input;
 };
 public static  void main(String[] args){
  Endpoint.publish("http://126.33.8.183:9999/GeoGlobeServer", new WSDemo());
 };

}

代码就是这么简单,那么就Run!

在浏览器敲入:http://126.33.8.183:9999/GeoGlobeServer?wsdl  回车。

ok 是不是很神奇。

转载请注明出处:http://www.cnblogs.com/likehua

原文地址:https://www.cnblogs.com/likehua/p/2141319.html