隨筆-42  評論-578  文章-1  trackbacks-0

          系統(tǒng)功能: 開發(fā)一個計算器服務(wù)CalculateService,這個服務(wù)包含加(plus)、減(minus)、乘(multiply)

          、除(divide)的操作。

          開發(fā)前準(zhǔn)備:
          1、安裝Eclipse-jee;
          2、下載Axis2的最新版本Axis2 1.4.1 Release,網(wǎng)址

          http://ws.apache.org/axis2/download/1_4_1/download.cgi ,選擇Standard Binary Distribution

          的.zip包即"axis2-1.4.1-bin.zip"這個文件,解壓縮得到的目錄名axis2-1.4.1,目錄內(nèi)的文件結(jié)構(gòu)如

          下:


          開發(fā)前配置:在Eclipse的菜單欄中,Window --> Preferences --> Web Service --> Axis2

          Perferences,在Axis2 runtime location中選擇Axis2解壓縮包的位置,設(shè)置好后,點"OK"即行。(如圖




          開發(fā)Web Service:
          1、新建一個Java Project,命名為"WS_01";
          2、新建一個class,命名為"CalculateService",完整代碼如下:

          package rong.service;

          /**
           * 計算器運算
           * 
          @author rongxinhua
           *
           
          */

          public class CalculateService {
              
              
          /**
               * 加法運算
               * 
          @param x 被加數(shù)
               * 
          @param y 加數(shù)
               * 
          @return x與y的和
               
          */

              
          public float plus(float x, float y){
                  
          return x + y ;
              }

              
              
          /**
               * 減法運算
               * 
          @param x 被減數(shù)
               * 
          @param y 減數(shù)
               * 
          @return x與y之差
               
          */

              
          public float minus(float x, float y){
                  
          return x - y ;
              }

              
              
          /**
               * 乘法運算
               * 
          @param x 被乘數(shù)
               * 
          @param y 乘數(shù)
               * 
          @return x與y的乘積
               
          */

              
          public float multiply(float x, float y){
                  
          return x * y ; 
              }

              
              
          /**
               * 除法運算
               * 
          @param x 被除數(shù)
               * 
          @param y 除數(shù)
               * 
          @return x與y的商
               
          */

              
          public float divide(float x, float y){
                  
          return x / y ;
              }


          }

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

          4、下一步(next),在出現(xiàn)的Web Services對象框,在Service implementation中點擊"Browse",進入

          Browse Classes對象框,查找到我們剛才寫的寫的CalculateService類。(如下圖)。點擊"ok",則回到

          Web Service話框。

          5、在Web Service對話框中,將Web Service type中的滑塊,調(diào)到"start service“的位置,將Client

          type中的滑塊調(diào)到"Test client"的位置。

          6、在Web Service type滑塊圖的右邊有個"Configuration",點擊它下面的選項,進入Service

          Deployment Configuration對象框,在這里選擇相應(yīng)的Server(我這里用Tomcat6.0)和Web Service

          runtime(選擇Apache Axis2),如下圖:

          7、點OK后,則返回到Web Service對話框,同理,Client type中的滑塊右邊也有"Configuration",也

          要進行相應(yīng)的置,步驟同上。完成后,Next --> next即行。

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

          了。

          9、等啟完后,點擊"next -- > next",一切默認(rèn)即行,最后,點擊完成。最后,出現(xiàn)如下界面:(Web

          Service Explorer),我們在這里便可測試我們的Web服務(wù)。


          10、測試比較簡單,例如,我們選擇一個"plus"的Operation,出現(xiàn)下圖,在x的輸入框中輸入2,在y的

          輸入框中輸入3,點擊"go",便會在status欄中顯示結(jié)果5.0。其他方法的測試也類似。

          到這里用Axis2與Eclipse整合開發(fā)的Web Service的服務(wù)端和客戶端就成功了。你也試試吧!
                  (*^-^*) 本文原創(chuàng),轉(zhuǎn)載請注明出處, http://www.aygfsteel.com/rongxh7謝謝! (*^-^*)



          本文原創(chuàng),轉(zhuǎn)載請注明出處,謝謝!http://www.aygfsteel.com/rongxh7(心夢帆影JavaEE技術(shù)博客)
              

          posted on 2009-05-21 15:13 心夢帆影 閱讀(50036) 評論(28)  編輯  收藏 所屬分類: WebServiceEclipse 、圖解教程

          評論:
          # re: [原創(chuàng)圖解教程] Axis2與Eclipse整合開發(fā)Web Service[未登錄] 2009-05-21 17:06 | vv
          www.xunleiyingyuan.cn www.57kx.cn www.gg140.com.cn www.gg138.com.cn www.gg137.com.cn www.gg136.com.cn www.gg135.com.cn
          www.s4ss.com.cn   回復(fù)  更多評論
            
          # re: [原創(chuàng)圖解教程] Axis2與Eclipse整合開發(fā)Web Service 2009-05-25 11:22 | ethenjustin
          樓主,我按照你的進行配置。在Server Deployment Configuration那張圖里,為什么Existing Servers我沒有任何選項?我用的是MyEclipse 7.1?我在Myeclipse下面能看到Tomcat 5.5,并且能從MyEclipse下能夠啟動。但是在那張圖里就看不到這個選項?  回復(fù)  更多評論
            
          # re: [原創(chuàng)圖解教程] Axis2與Eclipse整合開發(fā)Web Service 2009-06-08 18:51 | 心夢帆影
          @ethenjustin
          我用的是Eclipse-jee 3.4 ,可能是版本不同的原因吧,你自己摸索一下,我也是自己摸索著做的!呵呵  回復(fù)  更多評論
            
          # re: [原創(chuàng)圖解教程] Axis2與Eclipse整合開發(fā)Web Service 2009-06-23 19:16 | zu
          報Failed while installing Axis2 Web Services Core 1.1.個異常是怎么回事啊照著你的做的啊  回復(fù)  更多評論
            
          # re: [圖解教程] Axis2與Eclipse整合開發(fā)Web Service之一:簡單的計算服務(wù)例子[未登錄] 2009-10-10 14:34 | xy
          請問,我的window下preference里面沒有web service這一項怎么弄啊,謝謝  回復(fù)  更多評論
            
          # re: [圖解教程] Axis2與Eclipse整合開發(fā)Web Service之一:簡單的計算服務(wù)例子 2009-10-29 13:49 | santiago
          我的Eclipse下也沒有web service這一項,請問這個是要裝插件的么?  回復(fù)  更多評論
            
          # re: [圖解教程] Axis2與Eclipse整合開發(fā)Web Service之一:簡單的計算服務(wù)例子 2009-11-02 00:09 | 孫運盛
          6、在Web Service type滑塊圖的右邊有個"Configuration",點擊它下面的選項,

          請問在一步的時候 你設(shè)置的Service Project :tongji


          這個tongji是你事先建立好的一個Dynamic Web Project嗎?  回復(fù)  更多評論
            
          # re: [圖解教程] Axis2與Eclipse整合開發(fā)Web Service之一:簡單的計算服務(wù)例子 2009-12-16 15:42 | 網(wǎng)友
          看著亂 項目名哪出來的!  回復(fù)  更多評論
            
          # re: [圖解教程] Axis2與Eclipse整合開發(fā)Web Service之一:簡單的計算服務(wù)例子 2010-05-30 16:30 | qr
          謝謝分享! 但是我在第四步查找CalculateService類時, Service implement前面總是有個叉,無法進行下面的步驟,請問這是什么問題呀?  回復(fù)  更多評論
            
          # re: [圖解教程] Axis2與Eclipse整合開發(fā)Web Service之一:簡單的計算服務(wù)例子[未登錄] 2010-08-19 08:59 | frank
          @xy
          eclipse 3.6 中才有這一項
            回復(fù)  更多評論
            
          # re: [圖解教程] Axis2與Eclipse整合開發(fā)Web Service之一:簡單的計算服務(wù)例子 2010-12-20 13:37 | ols
          本人不適合新人  回復(fù)  更多評論
            
          # re: [圖解教程] Axis2與Eclipse整合開發(fā)Web Service之一:簡單的計算服務(wù)例子 2010-12-20 13:37 | ols
          本文不適合新人,剛才打錯字了  回復(fù)  更多評論
            
          # re: [圖解教程] Axis2與Eclipse整合開發(fā)Web Service之一:簡單的計算服務(wù)例子 2011-01-18 15:37 | tt
          樓主 我在部署的時候 提示Selection must be WSDL 這是為什么@ols
            回復(fù)  更多評論
            
          # re: [圖解教程] Axis2與Eclipse整合開發(fā)Web Service之一:簡單的計算服務(wù)例子 2011-03-01 15:42 | jf
          我按你方法做包了這樣的錯
          Unable to add the follwing facets to project testwebservice:
          Axis2 Web Services Extensions, Axis2 Web Services Core.  回復(fù)  更多評論
            
          # re: [圖解教程] Axis2與Eclipse整合開發(fā)Web Service之一:簡單的計算服務(wù)例子 2011-05-27 10:47 | wing2ofsky
          仔細查看報錯時"Detail"里面的信息,我出現(xiàn)這個錯誤是因為把AxisRuntime的路徑設(shè)置不對,導(dǎo)致不能找到有些文件  回復(fù)  更多評論
            
          # re: [圖解教程] Axis2與Eclipse整合開發(fā)Web Service之一:簡單的計算服務(wù)例子[未登錄] 2012-04-30 15:26 | 無名
          樓主,新建的工程是普通的java工程嗎?按照你的方法實驗,部署的時候報錯說:selection must be WSDL,想問樓主這是怎么回事?  回復(fù)  更多評論
            
          # re: [圖解教程] Axis2與Eclipse整合開發(fā)Web Service之一:簡單的計算服務(wù)例子 2012-05-26 09:50 | ylt
          @ethenjustin
          在"WS_01"項目上new --> other,找到"Web Services"下面的"Server“添加你的本地tomcat之類的服務(wù)器;
            回復(fù)  更多評論
            
          # re: [圖解教程] Axis2與Eclipse整合開發(fā)Web Service之一:簡單的計算服務(wù)例子 2012-05-28 10:06 | @無名
          你把你的服務(wù)第10步地址后加上?wsdl,如果能在瀏覽器里能打開才是正常的 如果不能 說明這個類有問題或你生成服務(wù)端的時候有問題@無名
            回復(fù)  更多評論
            
          # re: [圖解教程] Axis2與Eclipse整合開發(fā)Web Service之一:簡單的計算服務(wù)例子 2012-06-02 11:29 | zyp
          首先非常感謝作者。

          其次,本人是個菜菜的鳥,在按照您的教程進行時,在第4步出現(xiàn)問題。也就是傳說中的No server can be found and WebServiceProject does not exist. Choose an existing project or use the preferences to configure a server runtime.

          問題是這樣解決的:windows->preference->Server->Runtime Environment->add,加自己的tomcat就好了。  回復(fù)  更多評論
            
          # re: [圖解教程] Axis2與Eclipse整合開發(fā)Web Service之一:簡單的計算服務(wù)例子 2012-07-13 11:44 |
          @無名
          是不是方法返回的是復(fù)雜對象?
          我也出現(xiàn)該問題,如果POJO返回的只是簡單類型就不報錯  回復(fù)  更多評論
            
          # re: [圖解教程] Axis2與Eclipse整合開發(fā)Web Service之一:簡單的計算服務(wù)例子 2012-08-24 10:27 | demo
          你的圖片都是寫的tongji那個工程,你成功的是Ajax的工程,你這是在坑我們啊!照者你的步驟只能出現(xiàn)tongji那個工程,不能輸入?yún)?shù)!!?。?nbsp; 回復(fù)  更多評論
            
          # re: [圖解教程] Axis2與Eclipse整合開發(fā)Web Service之一:簡單的計算服務(wù)例子 2012-11-19 15:16 | kino
          額,我成功了。。。  回復(fù)  更多評論
            
          # re: [圖解教程] Axis2與Eclipse整合開發(fā)Web Service之一:簡單的計算服務(wù)例子 2012-11-19 15:19 | kino
          @kino
          補充,不是建一個普通的java工程,而是要建Dynamic Web Project,還有第十步地址真的要加上?wsdl  回復(fù)  更多評論
            
          # re: [圖解教程] Axis2與Eclipse整合開發(fā)Web Service之一:簡單的計算服務(wù)例子 2013-01-08 11:36 | xingyehehen
          在作者的基礎(chǔ)上要添加接口類和jar包  回復(fù)  更多評論
            
          # re: [圖解教程] Axis2與Eclipse整合開發(fā)Web Service之一:簡單的計算服務(wù)例子 2013-06-01 10:09 | FuYung
          我也出現(xiàn)這種情況了,你是怎么解決的呢?@tt
            回復(fù)  更多評論
            
          # re: [圖解教程] Axis2與Eclipse整合開發(fā)Web Service之一:簡單的計算服務(wù)例子 2014-04-17 17:57 | linxingwenabc
          為什么我會出現(xiàn)這個問題呢?
          Exception occurred during code generation for WSDL : org.apache.axis2.AxisFault: No operation found in the portType element  回復(fù)  更多評論
            
          # re: [圖解教程] Axis2與Eclipse整合開發(fā)Web Service之一:簡單的計算服務(wù)例子 2015-11-23 18:52 | wangxia
          為什么點擊go之后,status框中沒有結(jié)果  回復(fù)  更多評論
            
          # re: [圖解教程] Axis2與Eclipse整合開發(fā)Web Service之一:簡單的計算服務(wù)例子 2015-11-23 18:54 | wangxia
          為什么為什么呀,,前面配置的都是好的,配置成功了
          但是測試plus加法時,輸入1和2,點擊go之后,沒有返回結(jié)果  回復(fù)  更多評論
            
          主站蜘蛛池模板: 洛浦县| 乐平市| 焦作市| 化隆| 肇庆市| 保靖县| 镇江市| 安岳县| 罗江县| 崇礼县| 梅州市| 阿坝县| 阳西县| 察隅县| 华池县| 乐亭县| 红河县| 信宜市| 胶州市| 兴安盟| 新晃| 岗巴县| 涟源市| 张家港市| 隆德县| 普定县| 五台县| 安龙县| 无棣县| 沽源县| 石城县| 锦屏县| 木里| 南昌县| 屯门区| 滦平县| 朔州市| 井陉县| 金坛市| 扎鲁特旗| 乌审旗|