สร้างและปรับใช้ Simple Web Service และ Web Service Client ใน Eclipse
เผยแพร่แล้ว: 2019-10-20ทำตามขั้นตอนง่าย ๆ ด้านล่างเพื่อสร้างและปรับใช้ Web Service
และ Web Service Client
อย่างง่ายใน Eclipse IDE
ขั้นตอนที่ 1
ติดตั้ง Apache Tomcat และเพิ่มลงใน Eclipse ในแท็บเซิร์ฟเวอร์ – ฉันใช้ Tomcat version 9.0.10
ขั้นตอนที่ 2
สร้างโครงการเว็บไดนามิก (ชื่อ: CrunchifyWS
)

ขั้นตอนที่ 3
สร้างไฟล์จาวาภายใต้โฟลเดอร์ /src
คลิกขวาที่โฟลเดอร์ /src -> ใหม่ -> คลาส
- แพ็คเกจ:
crunchify.com.web.service
- ชื่อ:
CrunchifyHelloWorld.java

ขั้นตอนที่ 4
เปิดไฟล์ CrunchifyHelloWorld.java
และสร้างวิธีการหลักอย่างง่าย
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
package crunchify . com . web . service ; /** * @author Crunchify.com */ public class CrunchifyHelloWorld { public float addValue ( float value ) { return ( value + 10 ) ; } public float subtractValue ( float value ) { return ( value - 10 ) ; } } |
ขั้นตอนที่ -5
- คลิกขวาที่ไฟล์
CrunchifyHelloWorld.java -> Web Services -> Create Web Service
- เลือกตัวเลือกตามที่กล่าวไว้ในแผนภาพด้านล่าง
- คลิกเสร็จสิ้น

ขั้นตอนที่ 6
อาจใช้เวลาสักครู่เพื่อเสร็จสิ้นกระบวนการทั้งหมด และคุณควรเห็นโครงการใหม่ “ CrunchifyWSClient
” ที่สร้างขึ้น นี่คือโครงสร้างโครงการขั้นสุดท้าย:

ขั้นตอนที่ 7
CrunchifyWS
และ CrunchifyWSClient
ทั้งสองโปรเจ็กต์ควรถูกปรับใช้กับเซิร์ฟเวอร์โดยอัตโนมัติ
นอกจากนี้ Eclipse จะเปิด Web Service Test Client Window
โดยอัตโนมัติด้วย URL: http://localhost:8080/CrunchifyWSClient/sampleCrunchifyHelloWorldProxy/TestClient.jsp?endpoint=http://localhost:5922/CrunchifyWS/services/CrunchifyHelloWorld
ขั้นตอนที่-8
ตอนนี้คลิกที่ addValue(float)
, subtractValue(float)
และป้อนข้อมูลเพื่อตรวจสอบผลลัพธ์ที่อัปเดต

และคุณพร้อมแล้ว โปรดแจ้งให้เราทราบหากคุณพบปัญหาใดๆ กับขั้นตอนเหล่านี้
คุณได้รับข้อผิดพลาดด้านล่างหลังจากคลิกปุ่มเรียกใช้หรือไม่
1 2 |
Result Exception : java . net . ConnectException : Connection refused ( Connection refused ) Message : ; nested exception is : java . net . ConnectException : Connection refused ( Connection refused ) |

ทำตามขั้นตอนด้านล่าง:
- คลิกขวาที่ Tomcat
- คลิกเพิ่มและลบเพื่อดูแอปพลิเคชันที่เพิ่ม
- คลิกล้าง…
- คลิกเผยแพร่
- คลิกเริ่มใหม่

จะรัน WebService อีกครั้งหลังจากรีสตาร์ท Application หรือใหม่กว่าได้อย่างไร
นี่คือ URL ที่มีประโยชน์: http://localhost:8080/CrunchifyWSClient/sampleCrunchifyHelloWorldProxy/TestClient.jsp

หากคุณต้องการดาวน์โหลด CrunchifyHelloWorld.wsdl นี่คือ:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
<? xml version = "1.0" encoding = "UTF-8" ?> < wsdl : definitions targetNamespace = "http://service.web.com.crunchify" xmlns : apachesoap = "http://xml.apache.org/xml-soap" xmlns : impl = "http://service.web.com.crunchify" xmlns : intf = "http://service.web.com.crunchify" xmlns : wsdl = "http://schemas.xmlsoap.org/wsdl/" xmlns : wsdlsoap = "http://schemas.xmlsoap.org/wsdl/soap/" xmlns : xsd = "http://www.w3.org/2001/XMLSchema" > < ! -- WSDL created by Apache Axis version : 1.4 Built on Apr 22 , 2006 ( 06 : 55 : 48 PDT ) -- > < wsdl : types > < schema elementFormDefault = "qualified" targetNamespace = "http://service.web.com.crunchify" xmlns = "http://www.w3.org/2001/XMLSchema" > < element name = "subtractValue" > < complexType > < sequence > < element name = "value" type = "xsd:float" / > < / sequence > < / complexType > < / element > < element name = "subtractValueResponse" > < complexType > < sequence > < element name = "subtractValueReturn" type = "xsd:float" / > < / sequence > < / complexType > < / element > < element name = "addValue" > < complexType > < sequence > < element name = "value" type = "xsd:float" / > < / sequence > < / complexType > < / element > < element name = "addValueResponse" > < complexType > < sequence > < element name = "addValueReturn" type = "xsd:float" / > < / sequence > < / complexType > < / element > < / schema > < / wsdl : types > < wsdl : message name = "subtractValueResponse" > < wsdl : part element = "impl:subtractValueResponse" name = "parameters" > < / wsdl : part > < / wsdl : message > < wsdl : message name = "addValueResponse" > < wsdl : part element = "impl:addValueResponse" name = "parameters" > < / wsdl : part > < / wsdl : message > < wsdl : message name = "addValueRequest" > < wsdl : part element = "impl:addValue" name = "parameters" > < / wsdl : part > < / wsdl : message > < wsdl : message name = "subtractValueRequest" > < wsdl : part element = "impl:subtractValue" name = "parameters" > < / wsdl : part > < / wsdl : message > < wsdl : portType name = "CrunchifyHelloWorld" > < wsdl : operation name = "subtractValue" > < wsdl : input message = "impl:subtractValueRequest" name = "subtractValueRequest" > < / wsdl : input > < wsdl : output message = "impl:subtractValueResponse" name = "subtractValueResponse" > < / wsdl : output > < / wsdl : operation > < wsdl : operation name = "addValue" > < wsdl : input message = "impl:addValueRequest" name = "addValueRequest" > < / wsdl : input > < wsdl : output message = "impl:addValueResponse" name = "addValueResponse" > < / wsdl : output > < / wsdl : operation > < / wsdl : portType > < wsdl : binding name = "CrunchifyHelloWorldSoapBinding" type = "impl:CrunchifyHelloWorld" > < wsdlsoap : binding style = "document" transport = "http://schemas.xmlsoap.org/soap/http" / > < wsdl : operation name = "subtractValue" > < wsdlsoap : operation soapAction = "" / > < wsdl : input name = "subtractValueRequest" > < wsdlsoap : body use = "literal" / > < / wsdl : input > < wsdl : output name = "subtractValueResponse" > < wsdlsoap : body use = "literal" / > < / wsdl : output > < / wsdl : operation > < wsdl : operation name = "addValue" > < wsdlsoap : operation soapAction = "" / > < wsdl : input name = "addValueRequest" > < wsdlsoap : body use = "literal" / > < / wsdl : input > < wsdl : output name = "addValueResponse" > < wsdlsoap : body use = "literal" / > < / wsdl : output > < / wsdl : operation > < / wsdl : binding > < wsdl : service name = "CrunchifyHelloWorldService" > < wsdl : port binding = "impl:CrunchifyHelloWorldSoapBinding" name = "CrunchifyHelloWorld" > < wsdlsoap : address location = "http://localhost:8080/CrunchifyWS/services/CrunchifyHelloWorld" / > < / wsdl : port > < / wsdl : service > < / wsdl : definitions > |
แจ้งให้เราทราบหากคุณประสบปัญหาใด ๆ ในการดำเนินการนี้
