基本 WSDL 結構理解——(Web 服務描述語言)解釋
已發表: 2020-08-24您可能已經看過我之前關於 SOAP 與 REST 調用的帖子。 現在,公司正在轉向 REST 服務調用,但仍有大多數公司仍在使用 SOAP over REST。 本教程解釋了 WSDL(Web 服務描述語言)的基礎知識。
如果您有以下任何問題,那麼您來對地方了:
- 什麼是 Web 服務描述語言 (WSDL)?
- WSDL 教程
- Web 服務描述語言 (WSDL) 解釋
- WSDL 示例——Web 服務描述語言
Web 服務描述語言 (WSDL)
在 Java Web Development World 中,WSDL 是一種 XML 格式,用於將網絡服務描述為一組端點,這些端點對包含面向文檔或面向過程的信息的消息進行操作。
操作和消息被抽象描述,然後綁定到具體的網絡協議和消息格式以定義端點。 相關的具體端點組合成抽象端點(服務)。
WSDL 可擴展以允許描述端點及其消息,而不管使用何種消息格式或網絡協議進行通信,但是,本文檔中描述的唯一綁定描述瞭如何將WSDL
與 SOAP 1.1、HTTP GET/POST 和啞劇。

另一個必須閱讀:
- 在 Eclipse 中創建示例 WSDL 並生成客戶端
- 如何使用 JAX-RS 和 Jersey 使用 Java 構建 RESTful 服務(示例)
換句話說:WSDL 文檔將服務定義為網絡端點或ports
的集合。 在 WSDL 中,端點和消息的抽象定義與其具體的網絡部署或數據格式綁定是分開的。 這允許重用抽象定義: messages
是正在交換的數據的抽象描述,以及 port 類型是操作的抽象集合。
特定端口類型的具體協議和數據格式規範構成了可重用的binding
。 通過將網絡地址與可重用綁定相關聯來定義端口,並且端口集合定義服務。
因此,WSDL 文檔在網絡服務的定義中使用以下元素:
-
Types
——使用某種類型系統(例如XSD
)的數據類型定義的容器。 -
Message
- 正在傳達的數據的抽象、類型化定義。 -
Operation
——服務支持的操作的抽象描述。 -
Port Type
——一個或多個端點支持的一組抽像操作。 -
Binding
——特定端口類型的具體協議和數據格式規範。 -
Port
——定義為綁定和網絡地址組合的單個端點。 -
Service
——相關端點的集合。
元素 | 描述 |
---|---|
<類型> | 定義 Web 服務使用的(XML 模式)數據類型 |
<消息> | 定義每個操作的數據元素 |
<端口類型> | 描述可以執行的操作和涉及的消息。 |
<綁定> | 定義每種端口類型的協議和數據格式 |
示例:通過 HTTP 的 SOAP 1.1 請求/響應
示例 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 > |
工廠設計模式用示例解釋。

如果您有任何問題,請告訴我。