隨筆-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();
             //具體實(shí)現(xiàn)
            return WebServiceReceImpl.getInstance().send(userName, passWord, content, fromTerminalId, toTerminalId,remortAddress);
           }
          }

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

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

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

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

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

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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 邵阳市| 周宁县| 乐平市| 湖州市| 浦东新区| 临沭县| 精河县| 台州市| 邢台市| 来凤县| 金平| 建阳市| 乳山市| 明星| 锦屏县| 班玛县| 崇礼县| 宁晋县| 千阳县| 万盛区| 安多县| 平塘县| 满城县| 塘沽区| 漾濞| 会宁县| 华容县| 余江县| 扬州市| 白河县| 南华县| 类乌齐县| 公主岭市| 通道| 渑池县| 花莲市| 阳信县| 临泽县| 文安县| 盐城市| 高邮市|