qileilove

          blog已經轉移至github,大家請訪問 http://qaseven.github.io/

          Web service jws自帶測試例子

           新建一個服務端項目:
            1、定義一個接口如下:
          /**
          * 定義webservices接口
          * @author Administrator
          *
          */
          @WebService
          public interface IHelloService {
          public String sayHello(String name);
          public User  getUser(User user);
          }
            2.實現接口
          /**
          * 實現webservices接口
          * @author Administrator
          *
          */endpointInterface 實現的接口類
          @WebService(endpointInterface="com.chni.webservies.IHelloService")
          public class HelloServiceImpl implements IHelloService {
          public User getUser(User user) {
          // TODO Auto-generated method stub
          return null;
          }
          public String sayHello(String name) {
          // TODO Auto-generated method stub
          return name;
          }
          }
            3、啟動服務(執行下列main函數)
          public class TestService {
          public static void main(String[] args) {
          //服務地址
          String address="http://localhost:8989/u";
          Endpoint.publish(address, new HelloServiceImpl());
          }
          }
            4、在瀏覽器上輸入:http://127.0.0.1:8989/u?wsdl 看到以下信息:
          <!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.6 in JDK 6. --><!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.6 in JDK 6. --><definitions targetNamespace="http://impl.webservies.chni.com/" name="HelloServiceImplService"><import namespace="http://webservies.chni.com/" location="http://127.0.0.1:8989/u?wsdl=1"/><binding name="HelloServiceImplPortBinding" type="ns1:IHelloService"><soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/><operation name="getUser"><soap:operation soapAction=""/><input><soap:body use="literal"/></input><output><soap:body use="literal"/></output></operation><operation name="sayHello"><soap:operation soapAction=""/><input><soap:body use="literal"/></input><output><soap:body use="literal"/></output></operation></binding><service name="HelloServiceImplService"><port name="HelloServiceImplPort" binding="tns:HelloServiceImplPortBinding"><soap:address location="http://127.0.0.1:8989/u"/></port></service></definitions>
           5、新建一個客戶端項目
            6、在dos命令中使用 如下:d:\ws>wsimport -s . -p com.test.service http://127.0.0.1:8989/u?wsdl 表示意思是:在d盤有個ws文件夾 使用wsimport命令 -s生成客戶端源碼 -p 指定包名為com.test.service 后面為service 服務地址
            dos界面如下:
            好了你現在去你的d盤ws文件夾下的com這個文件夾考到新建客戶端項目的src目錄下
            7、新建一個java測試類如下:
          public class TestMail {
          public static void main(String[] args) {
          //建立客戶端(HelloServiceImplService 這個往什么地方來的去分析一下wsdl文件中有個service name=“new的這個HelloServiceImplService類”)建議還是去網上看看
          IHelloService cilent=new HelloServiceImplService().getHelloServiceImplPort();
          String abc=cilent.sayHello("XXX");
          System.out.println(abc);
          }
          }
            輸出的值為XXX 說明這個webservice搭建成功了 哈哈

          posted on 2014-03-20 11:12 順其自然EVO 閱讀(306) 評論(0)  編輯  收藏 所屬分類: 測試學習專欄

          <2014年3月>
          2324252627281
          2345678
          9101112131415
          16171819202122
          23242526272829
          303112345

          導航

          統計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 通榆县| 武强县| 扶沟县| 桃园县| 石阡县| 临海市| 寿阳县| 沁阳市| 澄城县| 樟树市| 宁远县| 达州市| 堆龙德庆县| 定陶县| 延津县| 资源县| 偃师市| 苍山县| 万载县| 庆安县| 通化市| 霸州市| 南部县| 濮阳市| 张北县| 姚安县| 卢氏县| 泊头市| 佛冈县| 平泉县| 宝兴县| 通河县| 中江县| 玛沁县| 阳新县| 云南省| 四平市| 宝应县| 定结县| 金昌市| 岳普湖县|