隨筆-6  評論-1  文章-0  trackbacks-0


          package rece.test;

          import javax.annotation.Resource;
          import javax.jws.WebMethod;
          import javax.jws.WebParam;
          import javax.jws.WebService;
          import javax.jws.soap.SOAPBinding;
          import javax.xml.ws.WebServiceContext;
          import com.sun.net.httpserver.HttpExchange;


          @WebService(targetNamespace = "http://rece.test.com", serviceName = "WebServiceRece")
          @SOAPBinding(style = SOAPBinding.Style.RPC)

          public class WebServiceRece
          {
           @Resource
           private WebServiceContext wsContext;

           @WebMethod
           public String sendZxdxSms(@WebParam(partName = "Username")String userName,
                   @WebParam(partName = "Password")String passWord,
                   @WebParam(partName = "Content")String content,
                   @WebParam(partName = "FromTerminalId")String fromTerminalId,
                   @WebParam(partName = "ToTerminalId")String toTerminalId
                   )
           {  
            //獲取提交請求的IP地址
            HttpExchange exchange  = (HttpExchange)wsContext.getMessageContext().get("com.sun.xml.internal.ws.http.exchange");
            String remortAddress = exchange.getRemoteAddress().getAddress().getHostAddress();
             //具體實現
            return WebServiceReceImpl.getInstance().send(userName, passWord, content, fromTerminalId, toTerminalId,remortAddress);
           }
          }

          在main方法中啟動這個webservice服務:
          Endpoint.publish("http://localhost:9898/test/send.jws", new WebServiceRece());

          打開wsdl
          http://localhost:9898/test/send.jws?wsdl

          生成客戶端
          在命令行下運行wsimport –keep http://localhost:9898/test/send.jws?wsdl,即可在當前目錄生成客戶端,-keep表示保留源文件,如果沒有-keep,則只生成class文件

          posted on 2008-04-29 14:52 天堂有路 閱讀(1667) 評論(1)  編輯  收藏

          評論:
          # re: java1.6實現webservice功能[未登錄] 2008-05-08 18:21 | steven
          請問lz
          com.sun.xml.internal.ws.http.exchange
          我怎么找不到啊?
          謝謝!  回復  更多評論
            

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 蓬安县| 长葛市| 尼玛县| 江陵县| 蕲春县| 桐城市| 吴旗县| 四川省| 乾安县| 太康县| 和顺县| 凤城市| 巴东县| 扶绥县| 大姚县| 中卫市| 普洱| 隆德县| 黔西| 呈贡县| 南木林县| 运城市| 乌鲁木齐县| 玛多县| 达日县| 叶城县| 修文县| 临沭县| 九台市| 遵义县| 许昌县| 新乐市| 丁青县| 普陀区| 宣汉县| 迁西县| 玉山县| 西畴县| 方正县| 阳山县| 河源市|