使用JAX-RS進行Web Service介面開發

來源:互聯網
上載者:User

標籤:string   右鍵   cep   package   結果   delegate   ges   技術分享   返回   

一、伺服器端

1、建立web項目,項目名稱為 WS_Server

2、建立包,並在該包下建立TestService類:

package com.test.webservice;public class TestService {    public static final String TITLE = "此訊息由WebService伺服器端返回: ";        public String test(String msg){        return TITLE + msg;    }}

3、將TestService.java類產生為伺服器端:

  (1)類名-右鍵-Web Service-Web Service

  (2)點擊 Next

  

  (3)點擊Next,選擇想要變成伺服器端的類,選中完畢後,直接點擊Finish按鈕。

  

  (4)可在包下發現多了一個TestServiceDelegate.java類;WEB-INF下多了一個sun-jaxws.xml檔案。

    

  (5)加入jar包,並允許Tomcat。  完成之後,在瀏覽器地址欄中輸入: http://localhost:8080/WS_Server/TestServicePort?wsdl ,結果如下:

 

 

 

 

 二、用戶端 

 (1)建立Web項目,項目名稱為:WS_Client

(2)建立Web Service Client,方法如伺服器端,可以使用如下快捷按鈕

(3)輸入伺服器端的WSDL地址: ,點擊Next,就會產生用戶端的檔案。

  (4)建立TestClient.java

  

package com.test.webservice;public class TestClient {    public static void main(String[] args) {        TestServiceDelegate test = new TestServiceService().getTestServicePort();        String result = test.test("--------調用伺服器端的test方法----------"); // 調用伺服器端的test方法        System.out.println("------&&&&&見證結果&&&&&&------");        System.out.println(result);    }}

  (5)將項目加入到Tomcat,啟動伺服器,並執行用戶端的TestClient,執行結果如下:

 

使用JAX-RS進行Web Service介面開發

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.