怎么在eclipse中訪問webservice


在eclipse創建webservice的方法:

1、在Eclipse的菜單欄中,Window --> Preferences --> Web Service --> Axis2 Perferences,在Axis2 runtime location中選擇Axis2解壓縮包的位置,設置好后,點"OK"即行。

2、新建一個webservice:

(1)新建一個Java Project,命名為"WebServiceTest1"(2)新建一個class,命名為"CalculateService",完整代碼如下:

package edu.sjtu.webservice;  

/** 

 * 計算器運算 

 * @author rongxinhua 

 */  

public class CalculateService {  

    //加法  

    public float plus(float x, float y) {  

        return x + y;  

    }  

    //減法  

    public float minus(float x, float y) {  

        return x - y;  

    }  

    //乘法  

    public float multiply(float x, float y) {  

        return x * y;  

   }  

    //除法  

    public float divide(float x, float y) {  

        if(y!=0)  

        {  

            return x / y;  

        }  

        else  

            return -1;  

    }  

}  

(3)在"WebServiceTest1"項目上new --> other,找到"Web Services"下面的"Web Service";

(4)下一步(next),在出現的Web Services對象框,在Service implementation中點擊"Browse",進入Browse Classes對象框,查找到我們剛才寫的寫的CalculateService類。(如下圖)。點擊"ok",則回到Web Service話框。

(5)在Web Service對話框中,將Web Service type中的滑塊,調到"start service“的位置,將Client type中的滑塊調到"Test client"的位置。

(6)在Web Service type滑塊圖的右邊有個"Configuration",點擊它下面的選項,進入Service Deployment Configuration對象框,在這里選擇相應的Server(這里用Tomcat6.0)和Web Service runtime(選擇Apache Axis2),如下圖:

(7)點OK后,則返回到Web Service對話框,同理,Client type中的滑塊右邊也有"Configuration",也要進行相應的置,步驟同上。完成后,Next --> next即行。進入到Axis2 Web Service Java Bean Configuration,我們選擇Generate a default services.xml,如下圖所示:

(8)到了Server startup對話框,有個按鍵"start server"(如下圖),點擊它,則可啟動Tomcat服務器了。

(9)等啟完后,點擊"next -- > next",一切默認即行,最后,點擊完成。最后,出現如下界面:(Web Service Explorer),我們在這里便可測試我們的Web服務。(使用瀏覽器打開的話使用如下地址:127.0.0.1:19189/wse/wsexplorer/wsexplorer.jsp?org.eclipse.wst.ws.explorer=3)。如下圖所示:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM