隨筆-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
          我怎么找不到啊?
          謝謝!  回復  更多評論
            

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


          網站導航:
           
          主站蜘蛛池模板: 大名县| 军事| 沈丘县| 咸宁市| 建阳市| 赤城县| 玉门市| 高淳县| 闻喜县| 香格里拉县| 德钦县| 天水市| 彰化县| 正镶白旗| 手机| 怀来县| 日土县| 陆良县| 永州市| 政和县| 五寨县| 泾阳县| 云梦县| 全椒县| 疏附县| 张掖市| 武冈市| 鹰潭市| 辽源市| 武山县| 兰考县| 安庆市| 洪雅县| 嘉善县| 阿瓦提县| 行唐县| 绍兴市| 宣恩县| 庄浪县| 昌图县| 金阳县|