Myeclipse開(kāi)發(fā)WebService接口服務(wù)端和客戶(hù)端_第1頁(yè)
Myeclipse開(kāi)發(fā)WebService接口服務(wù)端和客戶(hù)端_第2頁(yè)
Myeclipse開(kāi)發(fā)WebService接口服務(wù)端和客戶(hù)端_第3頁(yè)
Myeclipse開(kāi)發(fā)WebService接口服務(wù)端和客戶(hù)端_第4頁(yè)
Myeclipse開(kāi)發(fā)WebService接口服務(wù)端和客戶(hù)端_第5頁(yè)
已閱讀5頁(yè),還剩5頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、一、服務(wù)端發(fā)布WebService接口1、在Myeclipse中,選擇File->new->Web Service Project,然后輸入項(xiàng)目名稱(chēng),框中內(nèi)容按如下所示選擇即可,然后點(diǎn)擊next。2.點(diǎn)擊next后,出現(xiàn)如下畫(huà)面:3、再點(diǎn)擊next,勾選兩個(gè)框。4、點(diǎn)擊2次next后出現(xiàn)如下界面,勾選所有框5、點(diǎn)擊Finish完成后。在該項(xiàng)目上的Java Build Path,選擇Libraries標(biāo)簽,點(diǎn)擊Add Libirary,在彈出框中,選擇MyEclipse Library,如下圖所示:6、點(diǎn)擊next后,在彈出框中選擇JAX-WS 2.1 Libraries,并點(diǎn)擊Fi

2、nish,檢查L(zhǎng)ibraries標(biāo)簽中是否已經(jīng)添加上了剛添加的Lib7、在下面這個(gè)頁(yè)面上全部勾選:8、在TestServiceDemo/src目錄下,新建如下圖結(jié)構(gòu)的類(lèi): 其中IServiceHello類(lèi)為接口,ServiceHelloImpl類(lèi)為實(shí)現(xiàn),具體代碼如下:IServiceHello類(lèi):package com.mf5.app.service;public interface IServiceHellopublic String sayHello();public String sayHelloName(String name);ServiceHelloImpl類(lèi):packa

3、ge com.mf5.app.serviceimpl;import;import;import;import com.mf5.app.service.IServiceHello;WebService(targetNamespace="http:/demo.webservice",name="Hello")SOAPBinding(style=)public class ServiceHelloImpl implements IServiceHellopublic final String str = "WebService服務(wù)器返回消息.&quo

4、t;WebMethodpublic String sayHello()returnstr+"Hello!"WebMethodpublic String sayHelloName(String name)returnstr+name;9、在WEB-INF目錄下,新建一個(gè)文件,名稱(chēng)為:sun-,其中內(nèi)容如下:<?xml version="1.0" encoding="UTF-8"?><endpoints xmlnsjax-ws/ri/runtime" version="2.0"> &l

5、t;endpoint name="IServiceHello" implementation="com.mf5.app.serviceimpl.ServiceHelloImpl" url-pattern="/testservice"> </endpoint></endpoints>10、在web.xml文件中,在 <display-name>TestServiceDemo</display-name>  下面添加如下代碼:注意的是,在sun-中的urlurl-p

6、attern的值必須是一樣的。<listener> <listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class> </listener> <servlet> <servlet-name>testservice</servlet-name> <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</

7、servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>testservice</servlet-name> <url-pattern>/testservice</url-pattern> </servlet-mapping>11、可將TestServiceDemo部署在Myeclipse自帶的Tomcat中,并啟動(dòng)tomcat服務(wù)器。啟動(dòng)成功后,訪

8、問(wèn): http:/localhost:8080/TestServiceDemo/testservice,如果出現(xiàn)如下頁(yè)面,則說(shuō)明WebService部署成功。點(diǎn)擊頁(yè)面中的WSDL連接地址,訪問(wèn)的是該WebService的wsdl文件內(nèi)容:二、在Myeclipse上編寫(xiě)客戶(hù)端,訪問(wèn)接口1、同樣新建一個(gè)Web Service Project工程,名字為T(mén)estClient。2、打開(kāi)cmd命令,進(jìn)入到項(xiàng)目的src目錄下,輸入以下命令:wsimport  -keep http:/localhost:8080/TestServiceDemo/testservice?wsdl

9、回車(chē)后就會(huì)將wsdl上的接口信息生成java類(lèi)文件,放在src目錄下。3、刷新項(xiàng)目,可看到src目錄下有新文件生成。4、編寫(xiě)DemoTest類(lèi),測(cè)試是否能調(diào)用接口。代碼如下:package com.mf5.test;import;import;public class DemoTestpublic static void main(String args) /創(chuàng)建一個(gè)用于產(chǎn)生WebServiceImpl實(shí)例的工廠,WebServiceImplService類(lèi)是wsimport工具生成的ServiceHelloImplService factory = new ServiceHelloImplService(); /通過(guò)工廠生成一個(gè)WebServiceImpl實(shí)例,WebServiceImpl是wsimport工具生成的 Hello wsImpl = (); /調(diào)用WebService的sayHello方法 String resResult = ();("調(diào)用WebService的sayHello方法返回的結(jié)果是:"+resResult);("-"

溫馨提示

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

評(píng)論

0/150

提交評(píng)論