锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
1. Introduction
This document will outline the process of developing a JAX-WS web service and deploying it using MyEclipse 6.5 to the internal MyEclipse Tomcat server. The web service used in this tutorial will be a very simple calculator service that provides add, subtract, multiply and divide operations to the caller.
MyEclipse also supports developing web services using the existing XFire framework from previous MyEclipse releases. For folks needing to develop and deploy WebSphere JAX-RPC or WebSphere JAX-WS web services, please take a look at our MyEclipse Blue Edition of the MyEclipse IDE.
Additional resources covering web service creation using JAX-RPC, JAX-WS or XFire are included in the Resources section of this document.
2. System Requirements
This tutorial was created with MyEclipse 6.5. If you are using another version of MyEclipse (possibly newer), most of these screens and instructions should still be very similar.
If you are using a newer version of MyEclipse and notice portions of this tutorial looking different than the screens you are seeing, please let us know and we will make sure to resolve any inconsistencies.
3.鏂板緩涓涓伐紼?
寮濮嬫垜浠柊寤轟竴涓猈eb Service Project宸ョ▼File->New->Web Service Project(Optional Maven Support)
Note:A JAX-WS web service can also be generated in any existing Java EE 5 web project.
鎴戜滑緇欒繖涓伐紼嬪彇鍚嶄負WebServiceProject.娉ㄦ剰JAX-WS鏀寔鍙湪javaEE5鎴栨洿楂樼増鏈殑宸ョ▼涓槸鍙鐨勩傚鏋滀綘闇瑕佷嬌鐢ㄤ綆鐗堟湰鐨勫伐紼嬬被鍨?java1.4鎴栬?.3)錛岄偅涔堝彧鑳戒嬌鐢╔Fire Web Service浠f浛JAX-WS銆?
榪欓噷鎴戜滑浣跨敤涓婇潰鐨凧AX鈥擶S銆?
4.鍒涘緩鏈嶅姟綾?
鏈嶅姟綾誨氨鏄竴涓櫘閫氱殑java綾伙紝璐熻矗鎻愪緵鎴戜滑鎯寵鍙戝竷鐨勬墽琛屾柟娉曘傝繖閲屾垜浠啓涓涓畝鍗曠殑璁$畻鍣ㄧ被錛屽疄鐜板嚑涓吀鍨嬬殑璁$畻鍣ㄥ簲鐢ㄦ柟娉曪紝濡傚姞鍑忎箻闄ゃ?
棣栧厛鎴戜滑鍏堝緩涓涓寘錛學ebServiceProject->src->new->package,鍙栧悕com.myeclipseide.ws
璁╁悗鎴戜滑鍦ㄨ繖涓寘涓嬪緩涓涓被,Calculator.java.
鏍規嵁涓婇潰鎻愬埌鐨勶紝榪欎釜璁$畻鍣ㄧ被瀹炵幇璁$畻鍣ㄧ殑鍔犲噺涔橀櫎綆楁硶錛岀畝鍗曞疄鐜幫細
Java浠g爜
鍙互鐪嬪嚭錛岃繖涓被涓殑鏂規硶鏄潪甯哥畝鍗曠殑錛屾病鏈夌敤鍒扮壒孌婄殑娉ㄩ噴榪樻湁鎺ュ彛錛岀埗綾諱箣綾葷殑涓滆タ銆?
5.鍒涘緩涓涓猈eb Service
鍦ㄤ笂闈㈢殑宸ュ叿鏉′腑鐐瑰嚮鏂板緩Web Service
Note錛氬鏋滄病鏈夌殑璇濆彲浠ile->New->others->Myeclipse->WebService->webService
鐐瑰嚮涔嬪悗鍑虹幇鐨勫睆騫曪紝鍦⊿trategy涓夋嫨Bottom-up scenario錛屽洜涓烘垜浠凡緇忓緩绔嬪ソ浜咰alculator綾昏屼笖鎯蟲牴鎹畠寤虹珛JAX-WS鏈嶅姟銆?br />
涓嬮潰鏄垱寤虹殑鏈鍚庝竴涓睆騫曪紝浣犻渶瑕侀夋嫨鎻愪緵webService鏂規硶鐨刯avaBean錛屽湪鎴戜滑榪欎釜渚嬪瓙涓氨鏄垜浠凡緇忓緩绔嬪ソ鐨凜alculator綾匯?br />
濉ソ涔嬪悗錛孧yeclipse浼氳嚜鍔ㄥ府鎴戜滑濉弧鍏朵粬鐨勯」錛孲elect Generate WSDL in project and hit Finish.
鐐瑰嚮瀹屾垚涔嬪悗錛孧yeclipse浼氳嚜鍔ㄧ敓鎴怌alculatorDelegate浠g悊綾伙紝榪樻湁涓浜涘繀欏葷殑JAX-WS鎻忚堪絎︼紝鑰屼笖浼氳嚜鍔ㄥ湪鏈嶅姟鍣ㄧ洰褰曚笅鐨剋eb.xml涓厤緗甒ebService鐨勪竴浜沵appings錛屾柟渚垮皢webService閮ㄧ講鍒版湇鍔″櫒涓?
鍒版web service宸茬粡寤虹珛濂戒簡錛屾垜浠紑濮嬮儴緗插畠鐒跺悗榪涜嫻嬭瘯銆?
6.閮ㄧ講鍜屾祴璇晈ebService銆?
榪欓噷鎴戜滑涓嶄嬌鐢ㄧ敤Myeclipse鑷甫鐨則omcat鏈嶅姟鍣紝浣跨敤鑷繁搴旂粡鍦ㄧ數鑴戜腑閮ㄧ講濂界殑tomcat5.5銆?
鍦╯erver闈㈡澘涓彸鍑伙紝閫夋嫨configure
閮ㄧ講鑷繁鐨則omcat娉ㄦ剰閫夋嫨jdk瑕佽窡欏圭洰涓殑鐩稿悓銆?
鐜板湪瑕佸悜宸ョ▼涓鍏AX-WS鐨刯ar鍖?
鍦ㄩ」鐩悕縐頒笂鍙沖嚮->properties->Add Library->Myeclipse Libraries->鏈鍚庨潰鐨勪袱涓?
鐐瑰嚮瀹屾垚錛屽鍏ユ垚鍔熴?
Note錛歁yeclipse鑷甫鐨則omcat涓湁鑷甫鐨勮繖涓や釜jar鍖咃紝鍙互涓嶇敤瀵煎叆銆?
6.1閮ㄧ講
鍦ㄩ儴緗插ソ鐨則omcat鏈嶅姟鍣ㄤ笂鍙沖嚮閫夋嫨Add Deployment
鐐瑰嚮瀹屾垚銆?
6.2嫻嬭瘯
榪愯tomcat鏈嶅姟鍣紝鍦ㄥ伐鍏鋒爮涓偣鍑籰aunch WebService Explorer
鎵撳紑鍚庯紝鐐瑰嚮鍙充笂瑙掔殑WSDL瑙嗗浘錛屽彲浠ョ湅鍒頒笅闈㈢殑灞忓箷
鍦╓SDL URL涓~鍐欒礬寰勶細http://localhost:8888/WebServiceProject/CalculatorPort?WSDL
瑙i噴涓嬭礬寰勭粍鎴愶細
http://localhost:8888/鏄湇鍔″櫒鐨勮礬寰勶紝鎴戠殑绔彛鍙鋒槸8888錛屽彲浠ユ牴鎹嚜宸辯殑鏇存敼錛屼竴鑸兘鏄?080銆?
/WebServiceProject = We know by default the Web Context-root that is used to deploy(閮ㄧ講) web projects matches the name of the projects. (鍥犱負鎴戜滑娌℃湁涓鴻繖涓伐紼嬭嚜瀹氫箟鎴戜滑鐨刉eb Context-root錛屾墍浠ヤ粬灝辨槸榪欎釜宸ョ▼鐨勫悕瀛?
/CalculatorPort = As we saw from the last screenshot in Section #5, when our JAX-WS web service was generated, it was bound using a servlet-mapping in the web.xml file to the /CalculatorPort path.
XML浠g爜
WSDL = This is a universal query string argument that can be added to the end of any web service which will tell the web service to return it's full WSDL to the caller. In this case, the WSDL is returned to our Web Services Explorer tool which loads it up, and displays the web services exposed operations to us.
寮勬竻妤氫箣鍚庯紝鎴戜滑寮濮嬫祴璇曪紝姣斿鎴戜滑閫夋嫨add鏂規硶錛?
濉啓args錛岀偣鍑籫o錛屽湪status涓氨浼氭樉紺虹粨鏋溿?nbsp;
緇撴灉鏄紜殑銆?
7.鍒涘緩Webservice Client
鐜板湪鎴戜滑宸茬粡閮ㄧ講濂絎ebservice錛岃屼笖搴旂粡嫻嬭瘯榪囦簡錛岄偅鎴戜滑鏂板緩涓涓猈ebservice client錛屾潵璋冪敤Webservice鎻愪緵鐨勬柟娉曘?
7.1鏂板緩涓涓猨ava project錛岀粰浠栧彇涓悕瀛椼傛瘮濡傛垜浠彨瀹僀lientofWebService
鍦ㄥ伐鍏鋒潯涓偣鍑籲ew Web Service Client
鐒跺悗鎸夌収浠ヤ笅姝ラ鎿嶄綔錛?
The last step of the web service client creation is to specify either a WSDL File or a WSDL URL for the wizard to retrieve the web service WSDL from. In our case we are using the URL and generate the client into the new package com.myeclipseide.ws.client:
http://localhost:8888/WebServiceProject/CalculatorPort?WSDL
鐐瑰嚮Next鐭ラ亾瀹屾垚銆?
鍙互鐪嬪埌鍦ㄦ柊寤虹殑java project ClientofWebService涓紝src鏂囦歡澶逛笅浜х敓浜嗚澶氱殑鏂囦歡錛屾牴鎹悕縐版垜浠ぇ浣撳彲浠ヤ簡瑙e叾鎰忔濓紝鍙互鎵撳紑鐪嬩竴涓嬫簮浠g爜錛屽叾瀹炰笉闅劇悊瑙c傛瘮濡俛dd鏂囦歡錛屽氨鏄疌alculator綾諱腑add鏂規硶鐨勪袱涓弬鏁扮殑get鍜宻et鏂規硶銆傚叾浠栫被浼箋?
鎴戜滑鍦ㄦ枃浠跺す涓嬭涓涓被test.java鍐欎竴涓猰ain鍑芥暟嫻嬭瘯
Java浠g爜
榪愯寰楀埌濡備笅緇撴灉錛?
1. 3+7=10
2. 12-2=10
3. 9*9=81
4. 40/2=20
嫻嬭瘯瀹屾垚銆?
鏈枃鏉ヨ嚜CSDN鍗氬錛岃漿杞借鏍囨槑鍑哄錛歨ttp://blog.csdn.net/foart/archive/2009/06/21/4287515.aspx