基本 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
,它是正在交换的数据的抽象描述,以及端口类型,它是操作的抽象集合。
特定端口类型的具体协议和数据格式规范构成了可重用的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 > |
工厂设计模式用示例解释。

如果您有任何问题,请告诉我。