ความเข้าใจโครงสร้าง WSDL พื้นฐาน – (ภาษาคำอธิบายบริการเว็บ) อธิบาย
เผยแพร่แล้ว: 2020-08-24คุณอาจเคยเห็นโพสต์ก่อนหน้าของฉันในการโทร SOAP กับ REST วันนี้บริษัทต่างๆ เปลี่ยนไปใช้การเรียกบริการ REST แต่ก็ยังมีบริษัทส่วนใหญ่ที่ยังคงใช้ SOAP แทน REST บทช่วยสอนนี้จะอธิบายพื้นฐานของ WSDL (ภาษาคำอธิบายบริการเว็บ)
หากคุณมีคำถามใด ๆ ด้านล่างแสดงว่าคุณมาถูกที่แล้ว:
- ภาษาคำอธิบายบริการเว็บ (WSDL) คืออะไร?
- WSDL กวดวิชา
- คำอธิบายภาษาคำอธิบายบริการเว็บ (WSDL)
- ตัวอย่างของ WSDL – คำอธิบายบริการเว็บ ภาษา
ภาษาคำอธิบายบริการเว็บ (WSDL)
ใน Java Web Development World WSDL เป็นรูปแบบ XML สำหรับการอธิบายบริการเครือข่ายเป็นชุดของปลายทางที่ทำงานบนข้อความที่มีข้อมูลเชิงเอกสารหรือตามขั้นตอน
มีการอธิบายการดำเนินการและข้อความอย่างเป็นนามธรรม จากนั้นผูกกับโปรโตคอลเครือข่ายที่เป็นรูปธรรมและรูปแบบข้อความเพื่อกำหนดปลายทาง จุดสิ้นสุดที่เป็นรูปธรรมที่เกี่ยวข้องจะรวมกันเป็นจุดสิ้นสุดที่เป็นนามธรรม (บริการ)
WSDL สามารถขยายได้เพื่อให้คำอธิบายของจุดปลายและข้อความของจุดปลายและข้อความของปลายทางนั้น โดยไม่คำนึงถึงรูปแบบข้อความหรือโปรโตคอลเครือข่ายที่ใช้ในการสื่อสาร อย่างไรก็ตาม การผูกเฉพาะที่อธิบายไว้ในเอกสารนี้อธิบายวิธีใช้ WSDL
ร่วมกับ SOAP 1.1, HTTP GET/POST และ ไมม์

ต้องอ่านอีก:
- สร้างตัวอย่าง WSDL ใน Eclipse และสร้างไคลเอนต์
- วิธีสร้าง RESTful Service ด้วย Java โดยใช้ JAX-RS และ Jersey (ตัวอย่าง)
กล่าวอีกนัยหนึ่ง: เอกสาร WSDL กำหนด บริการ เป็นคอลเลกชันของปลายทางเครือข่าย หรือ ports
ใน WSDL คำจำกัดความนามธรรมของปลายทางและข้อความจะถูกแยกออกจากการปรับใช้เครือข่ายที่เป็นรูปธรรมหรือการผูกรูปแบบข้อมูล ซึ่งช่วยให้สามารถนำคำจำกัดความนามธรรมมาใช้ซ้ำได้: messages
ซึ่งเป็นคำอธิบายที่เป็นนามธรรมของข้อมูลที่กำลังแลกเปลี่ยน และประเภทพอร์ตที่เป็นการรวบรวมการดำเนินการที่เป็นนามธรรม
โปรโตคอลที่เป็นรูปธรรมและข้อกำหนดรูปแบบข้อมูลสำหรับพอร์ตประเภทใดประเภทหนึ่งถือเป็นการ binding
ที่นำกลับมาใช้ใหม่ได้ พอร์ตถูกกำหนดโดยการเชื่อมโยงที่อยู่เครือข่ายกับการผูกที่ใช้ซ้ำได้ และชุดของพอร์ตจะกำหนดบริการ
ดังนั้น เอกสาร WSDL จะใช้องค์ประกอบต่อไปนี้ในคำจำกัดความของบริการเครือข่าย:
-
Types
– คอนเทนเนอร์สำหรับการกำหนดประเภทข้อมูลโดยใช้ระบบบางประเภท (เช่นXSD
) -
Message
– คำจำกัดความที่เป็นนามธรรมของข้อมูลที่กำลังสื่อสาร -
Operation
– คำอธิบายที่เป็นนามธรรมของการดำเนินการที่สนับสนุนโดยบริการ -
Port Type
– ชุดการดำเนินการที่เป็นนามธรรมที่รองรับโดยจุดปลายหนึ่งจุดหรือมากกว่า -
Binding
– โปรโตคอลที่เป็นรูปธรรมและข้อกำหนดรูปแบบข้อมูลสำหรับพอร์ตประเภทใดประเภทหนึ่ง -
Port
– ปลายทางเดียวที่กำหนดเป็นการรวมและที่อยู่เครือข่าย -
Service
– การรวบรวมปลายทางที่เกี่ยวข้อง
องค์ประกอบ | คำอธิบาย |
---|---|
<ประเภท> | กำหนดประเภทข้อมูล (XML Schema) ที่ใช้โดยบริการเว็บ |
<ข้อความ> | กำหนดองค์ประกอบข้อมูลสำหรับการดำเนินการแต่ละครั้ง |
<portType> | อธิบายการดำเนินการที่สามารถทำได้และข้อความที่เกี่ยวข้อง |
<ผูกพัน> | กำหนดโปรโตคอลและรูปแบบข้อมูลสำหรับพอร์ตแต่ละประเภท |
ตัวอย่าง: คำขอ/ตอบกลับ SOAP 1.1 ผ่าน HTTP
ตัวอย่างเอกสาร XML 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 |
<? xml version = "1.0" ?> < definitions name = "StockQuote" targetNamespace = "http://example.com/stockquote.wsdl" xmlns : tns = "http://example.com/stockquote.wsdl" xmlns : xsd1 = "http://example.com/stockquote.xsd" xmlns : soap = "http://schemas.xmlsoap.org/wsdl/soap/" xmlns = "http://schemas.xmlsoap.org/wsdl/" > < types > < schema targetNamespace = "http://example.com/stockquote.xsd" xmlns = "http://www.w3.org/2000/10/XMLSchema" > < element name = "TradePriceRequest" > < complexType > < all > < element name = "tickerSymbol" type = "string" / > < / all > < / complexType > < / element > < element name = "TradePrice" > < complexType > < all > < element name = "price" type = "float" / > < / all > < / complexType > < / element > < / schema > < / types > < message name = "GetLastTradePriceInput" > < part name = "body" element = "xsd1:TradePriceRequest" / > < / message > < message name = "GetLastTradePriceOutput" > < part name = "body" element = "xsd1:TradePrice" / > < / message > < portType name = "StockQuotePortType" > < operation name = "GetLastTradePrice" > < input message = "tns:GetLastTradePriceInput" / > < output message = "tns:GetLastTradePriceOutput" / > < / operation > < / portType > < binding name = "StockQuoteSoapBinding" type = "tns:StockQuotePortType" > < soap : binding style = "document" transport = "http://schemas.xmlsoap.org/soap/http" / > < operation name = "GetLastTradePrice" > < soap : operation soapAction = "http://example.com/GetLastTradePrice" / > < input > < soap : body use = "literal" / > < / input > < output > < soap : body use = "literal" / > < / output > < / operation > < / binding > < service name = "StockQuoteService" > < documentation > My first service < / documentation > < port name = "StockQuotePort" binding = "tns:StockQuoteBinding" > < soap : address location = "http://example.com/stockquote" / > < / port > < / service > < / definitions > |

SOAP 2.0 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 |
< ! -- Crunchify ' s example of WSDL 2.0 -- > <? xml version = "1.0" encoding = "UTF-8" ?> < definitions xmlns = "http://www.w3.org/ns/wsdl" xmlns : tns = "http://www.tmsws.com/wsdl20sample" xmlns : whttp = "http://schemas.xmlsoap.org/wsdl/http/" xmlns : wsoap = "http://schemas.xmlsoap.org/wsdl/soap/" targetNamespace = "http://www.tmsws.com/wsdl20sample" > < ! -- Abstract type -- > < types > < xs : schema xmlns : xs = "http://www.w3.org/2001/XMLSchema" xmlns = "http://www.tmsws.com/wsdl20sample" targetNamespace = "http://crunchify.com/wsdl20" > < xs : element name = "request" > . . . add your code here . . . < / xs : element > < xs : element name = "response" > . . . add your code here . . . < / xs : element > < / xs : schema > < / types > < ! -- Abstract interfaces -- > < interface name = "CrunchifyItem" > < fault name = "ErrorDescription" element = "tns:response" / > < operation name = "Get" pattern = "http://www.w3.org/ns/wsdl/in-out" > < input messageLabel = "In" element = "tns:request" / > < output messageLabel = "Out" element = "tns:response" / > < / operation > < / interface > < ! -- Concrete Binding Over HTTP -- > < binding name = "HttpBinding" interface = "tns:CrunchifyItem" type = "http://www.w3.org/ns/wsdl/http" > < operation ref = "tns:Get" whttp : method = "GET" / > < / binding > < ! -- Concrete Binding with SOAP -- > < binding name = "SoapBinding" interface = "tns:CrunchifyItem" type = "http://www.w3.org/ns/wsdl/soap" wsoap : protocol = "http://www.w3.org/2003/05/soap/bindings/HTTP/" wsoap : mepDefault = "http://www.w3.org/2003/05/soap/mep/request-response" > < operation ref = "tns:Get" / > < / binding > < ! -- Web Service offering endpoints for both bindings -- > < service name = "ServiceOne" interface = "tns:CrunchifyItem" > < endpoint name = "HttpEndpoint" binding = "tns:HttpBinding" address = "http://www.example.com/rest/" / > < endpoint name = "SoapEndpoint" binding = "tns:SoapBinding" address = "http://crunchify.com/soap/" / > < / service > < / definitions > |
รูปแบบการออกแบบโรงงานอธิบายด้วยตัวอย่าง

แจ้งให้เราทราบหากคุณมีคำถามใดๆ