隨筆-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 天堂有路 閱讀(1668) 評論(1)  編輯  收藏

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

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


          網站導航:
           
          主站蜘蛛池模板: 新晃| 原阳县| 利津县| 宁国市| 扶余县| 绵竹市| 平谷区| 南丰县| 崇州市| 微博| 固阳县| 冕宁县| 亚东县| 库尔勒市| 白山市| 文水县| 普兰店市| 乌审旗| 岢岚县| 八宿县| 都匀市| 东阳市| 旅游| 澄城县| 新密市| 页游| 雅江县| 太和县| 房产| 双牌县| 阿拉善右旗| 抚松县| 兴业县| 阿克| 京山县| 石渠县| 汉沽区| 江源县| 句容市| 河南省| 望城县|