MyEclipse開發和測試WebService實例詳解_第1頁
MyEclipse開發和測試WebService實例詳解_第2頁
MyEclipse開發和測試WebService實例詳解_第3頁
MyEclipse開發和測試WebService實例詳解_第4頁
MyEclipse開發和測試WebService實例詳解_第5頁
已閱讀5頁,還剩1頁未讀 繼續免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、使用 myeclipse web service 來迅速開發和測試一個 helloworld web service, 其中包括:1. 介紹了 myeclipse web services 的基本概念2. 創建一個 myeclipse web services i程3. 創建一個簡單的 helloworld web service4. 在web容器中,如tomcat 5中部署web service5. 使用 web services explorer 來測試部署的 web servicesxfire java soap 框架概述myeclipse web services是建立在xfire j

2、ava soap框架和工具基礎上的,xfire 是一款開源的java soap框架。它擁有一個輕量級的信息處理模塊,通過stax 來與soap信息相結合。提供了一個工作在web services下的簡單api,支持pojo 和 schema 開發.xfire 支持 web services standards, spring 整合,支持 jb1 , 支持 jaxb , xmlbeans, java 5 和 jax-ws.并支持 http, jms, xmpp, in-memory 傳輸協議.一創建web service x程在myeclipse 5. 0中引入了一個新的工程類型即web ser

3、vice工程,該工程擴展 了 myeclipse web project來支持額外的web service配置,開發和部署本部分 將使用web services project wizard來創建和配置一個新的web service projects web service wizard 將完成下列的動作:創建 myeclipse j2ee web project在工程中的web. xml文件中配置xfire servlet創建xfire services, xml配置文件在工程中的構建路徑中添加myeclipse-xfire類庫添加一個指定的myeclipse web project bui

4、lder至ljprojects文件,以便部署 services, xml 文件到它合適的位置.如:/web-inf/classes/meta-inf/xf ire/運行 web service project wizard該向導包括三個頁面,page-1搜集web project配置細節,page-2搜集xfire 配置細節,page-3在新建的構建路徑屮配置xfire類庫1執行 web services project wizard.1) 選擇 file>new>other2) .擴展myeclipse種類按照j2ee工程的種類3) .選擇web services project

5、然后點擊next,如圖所示figure-1: new project wizard launcher2. 添加 project name,點擊 nextfigure-2: page-2, collecting web configuration details3. 在向導的page-2中添加xfire servlet和service, xml文件的配置信息,按照 默認的值即可.figure-3: xfire servlet and services, xml configuration4. 在向導的page-3屮選擇類庫添加到工程的構建路徑屮,其屮xfire core library是需要的,

6、如果要在工程中開發一個客戶端應用,xfire http client libraries也是需要的.figure-4: selecting xfire libraries to add to new web service project buildpath5選擇finish完成web service工程的創建過程figure-5,顯示了新創建的helloworld web service工程的組織結構,web service工程和一個標準的myeclipse web工程很相似.xfire web service配 置元素如圖紅色區域顯示:figure-5: web services arti

7、facts of a new web service project二 myeclipse 開發z創建 web service-code-first strategy在這部分將用 myeclipse web service wizard 并通過使用 code-first strategy 來創建一個 hellowor 1 dservice 示例.1執行 myecl ipse web service wizard,有兩種方法來執行 myecl ipse web service wizard方 法1.從myeclipse perspective toolbar中來執行向導在打開的web servi

8、ce wizard上的workbench上來選擇新web service按鈕方法2.從workbench menubar執行向導 hk workbench menubar 選擇:filc>ncw>othcr>myecl ipsc>wcb servicefigure-6: launching web service wizard2. 在 page-1 選擇 helloworld 工程并選擇 create web service from java bean3. 選擇 next 到 page-24. 填寫 web service 的名字 ilelloworldservice

9、5. 選擇jeiv3 source folder或者選擇new按鈕來新建一個source folder6. 填寫java package或者通過選擇browse按鈕來選擇一個己經存在的package. 也可以選擇new按鈕來新建一個java package注意:對service接口和service執行的類的默認值是基于所填入web service 名字來產生的.7. 選擇next來初始化web service的創建過程figure-8: page-2 of new web service wizard.該向導產生了 ihelloworldservice java 接口和 he 11 owor

10、1 dserviceimp 1 java 類.并且在services, xml配置文件中創建了一個實體(如圖所示),注意到 example (string message)方法在接口類中產生,當web service部署后作為一個 測試操作.figurc-9: newly crcated helloworld interface and implcmentation class三.myeclipse 開發之部署 web service projectweb service可以部署在任何myeclipse支持的j2ee應用服務器上,該部分將演 示如何在tomcat 5 web容器上部署hello

11、world工程.3. 1 部署 helloworld web service projectfigure-10顯示了如何部署helloworld應用.1. 從 server manager 中選擇 depl oyer 按鈕(step-1)2. 在 server deploymcnts 對話框屮選擇 add to create a new deployment (step-2)3. 在 new deployment 對話框中選擇 helloworld 工程并選擇 exploded archive 選項4. 在 new deployment 對話框選擇 finish 來將 hel loworld

12、在 tomcat 5 默認的 位置屮打包為war5. 選擇ok完成部署figure-10: three-step deployment process新hel loworld war部署將出現在server manager視圖中tomcat 5節點下.figurel 1: servers manager view depicting deployed hel loworld web service project四myeclipse開發之啟動tomcat服務器五. myeclipse 開發之使用 web service explorer 測試 web servicemyecl ipse 提供了

13、一個 web service explorer 來測試 web service.1. 在 myecl ipse perspective 中選擇 toolbar button 來執行 web service explorerfigure-15: web services explorer launch button on workbench toolbar2. 選擇 wsdl 模式(figure-16)3. 在活動面板屮鍵入ilelloworldservice wsdl文檔的urlhttp: /localhost:8080/ilelloworld/services/ilelloworldserv

14、ice?wsdl, w cb service explorer將下載自動產生的wsdl文檔,該wsdl文檔由xfirc framework,并產生一系列的操作能夠調用service.4. 在活動面板中選擇example操作并在ino域中鍵入hel loworld5. 選擇go按鈕來調用在hel loworldservice上的example操作,,結果出現在 status而板上figure-16: web services explorer testing hellowor1dservice六. myeclipse開發之創建java test客戶端xfire提供了一個動態的代理框架,能夠讀取w

15、sdl文檔和創建潛在的消息服務使 java類來執行在web service的行為.該部分將為hel loworld web service寫 一個 java web service 客戶端6. 1增加xfire類庫配置為了使example client能夠在helloworld工程中運行,需要增加xfire http cl ient類庫到工程的構建路徑中.1. 在 package explore 視圖中右擊 helloworld i程選擇 build path>add library2. 選擇 myeclipse libraries3. 選擇 xfire http client libr

16、ariesfigurc-17: choosing the xfire http client libraries4. 選擇 finish6. 2 創建 helloworldclient 類執彳亍java類向導來創建helloworldclient類figure-18: helloworldclient defined in new java class wizard.代碼如下:1. publicstatic voidmain(string args) 2. service srvcmodel =new3. objectservicefactor、y(). create (ihelloworld

17、service. class);4. xfireproxyfactory factory-5. new xfireproxyfactory(xfirefactory. newlnstance() getxfire();6. stringhelloworldurl二7. http:/localhost:8080/helloworld/services/helloworldservice9. try10. ihclloworldscrvice srve =(ihc11owor1dscrv i c e)fac tory.create (srvcmodel, helloworldurl);11. string resuit 二 srve.example ("hello world");12. system, out. print

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論