xml WSDL 中的 <binding> 和 <portType> 之间有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4511346/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What's the difference between <binding> and <portType> in WSDL?
提问by clamp
Both <binding>and <portType>seem to define an operation and its message. I don't quite understand, why are they both necessary?
双方<binding>并<portType>似乎定义操作和它的消息。我不太明白,为什么它们都是必要的?
回答by Premraj
portType(Analogs to Java interface)
portType(类似于 Java 接口)
- PortType is an abstraction part of WSDL.
- An abstract set of operations supported by one or more endpoints.
- PortType 是 WSDL 的抽象部分。
- 一个或多个端点支持的一组抽象操作。
binding
捆绑
- Binding is an concrete part of WSDL.
- Describes how the operation is invoked by specifying concrete protocol and data format specifications for the operations and messages.
SOAP Binding:
SOAP binding allows eitherdocumentorrpcstylewith eitherencodingorliteral. Encodingindicates how a data value should be encoded in an XML format (These rules specify how "something" is encoded/serialized to XML and then later decoded/de-serialized from XML back to "something"). Literalmeans that the data is serialized according to a schema (this is just plain XML data). With transportation type http, jms, smtp...HTTP GET & POST binding:
WSDL includes a binding for HTTP 1.1's GET and POST verbs in order to describe the interaction between a Web Browser and a web site.MIME binding:WSDL includes a way to bind abstract types to concrete messages in some MIME format.
- 绑定是 WSDL 的一个具体部分。
- 通过为操作和消息指定具体的协议和数据格式规范来描述如何调用操作。
SOAP绑定:
SOAP绑定或者允许document或rpc风格有两种encoding或literal。编码指示数据值应如何以 XML 格式编码(这些规则指定如何将“某物”编码/序列化为 XML,然后从 XML 解码/反序列化回“某物”)。字面意思是数据根据模式序列化(这只是普通的 XML 数据)。具有传输类型http、jms、smtp...HTTP GET 和 POST 绑定:
WSDL 包括对 HTTP 1.1 的 GET 和 POST 动词的绑定,以描述 Web 浏览器和网站之间的交互。MIME 绑定:WSDL 包括一种将抽象类型绑定到某些 MIME 格式的具体消息的方法。
In WSDL 2.0 :
在 WSDL 2.0 中:
- PortTypes renamed to interfaces
- Ports renamed to endpoints
- Removed message constructs
- 端口类型重命名为接口
- 端口重命名为端点
- 删除的消息结构
Useful links
有用的链接
回答by LCJ
Interfaces (wsdl:portType)
接口 (wsdl:portType)
The WSDL portType element defines a group of operations (sometimes known as an interface).
WSDL portType 元素定义了一组操作(有时称为接口)。
The operation elements contain a combination of input and output elements. There can be a fault element when you have an output element. The order of these elements defines the message exchange pattern (MEP) (One-way, Request – Response, etc)
操作元素包含输入和输出元素的组合。当您有一个输出元素时,可能会有一个错误元素。这些元素的顺序定义了消息交换模式 (MEP)(单向、请求 - 响应等)


wsdl:binding
wsdl:绑定
The WSDL binding element describes the concrete details of using a particular portType with a given protocol.
WSDL 绑定元素描述了将特定端口类型与给定协议一起使用的具体细节。


回答by Cratylus
PortType defines the abstract interfaceof a web service.
Conceptually it is like a Java interface since it defines an abstract type and related methods.
In WSDL the port type is implementedby the binding and service elements which indicate the protocols, encoding schemes etc to be used by a web service implementation
I.e. the binding specifies concrete implementation detailsand essentially maps a portType to a set of protocols (HTTP and SOAP) message styles (Document/RPC) and encodings (literal)
Is the distiction clear now?
PortType 定义了 Web 服务的抽象接口。
从概念上讲,它就像一个 Java 接口,因为它定义了一个抽象类型和相关方法。
在 WSDL 中,端口类型由 binding 和 service 元素实现,这些元素指示Web 服务实现要使用的协议、编码方案等,
即绑定指定具体的实现细节,并且本质上将 portType 映射到一组协议(HTTP 和 SOAP ) 消息样式(文档/RPC)和编码(文字)
现在区分清楚了吗?
回答by Shirgill Farhan
portType
A single Web servicecan support a number of different protocols. The structure of the data depends on the protocol that you use to invoke the Web service. Because of this, you need a way to map from the operations to the endpointsfrom which they can be accessed. The portTypeelement takes care of this mapping.
端口类型
一个单一的Web服务可支持多种不同的协议。数据的结构取决于您用来调用 Web 服务的协议。因此,您需要一种将操作映射到可以访问它们的端点的方法。该端口类型元素采用这种映射的照顾。
You can place a portType definition for each of the protocols available to you for this Web service. For instance, you can have individual portType definitions for using SOAP, HTTP-POST, and HTTP-GET. The operation name is the method available from the Web service.
您可以为该 Web 服务可用的每个协议放置一个 portType 定义。例如,您可以使用单独的 portType 定义来使用SOAP、HTTP-POST 和 HTTP-GET。操作名称是可从 Web 服务获得的方法。
binding
You can define how the end user binds to a port where the operation is obtainable. You do this by using the element.
绑定
您可以定义最终用户如何绑定到可以获得操作的端口。您可以通过使用元素来做到这一点。
回答by flyredeagle
wsdl:portType goes with wsdl:operation i.e. we are in the realms of messages and xml as such
wsdl:portType 与 wsdl:operation 一起使用,即我们处于消息和 xml 的领域中
but wsdl:binding goes with soap:binding and soap:operation i.e. we are in the realm of encoding, addresses, headers and rpc
但是 wsdl:binding 与soap:binding 和soap:operation 一起使用,即我们处于编码、地址、标头和rpc 的领域
e.g. from : http://www.w3.org/TR/wsdl#_soap-b
例如来自:http: //www.w3.org/TR/wsdl#_soap-b
<binding name="StockQuoteSoap" type="tns:StockQuotePortType">
<soap:binding style="document" transport="http://example.com/smtp"/>
<operation name="SubscribeToQuotes">
<input message="tns:SubscribeToQuotes">
<soap:body parts="body" use="literal"/>
<soap:header message="tns:SubscribeToQuotes" part="subscribeheader" use="literal"/>
.....
.....
<binding name="StockQuoteSoapBinding" type="tns:StockQuotePortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="GetTradePrice">
<soap:operation soapAction="http://example.com/GetTradePrice"/>
<input>
<soap:body use="encoded" namespace="http://example.com/stockquote"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
...
...
and from paragraph 3.2 all possible details about lower level communication stuff:
从第 3.2 段开始,所有关于低级通信内容的可能细节:
The SOAP Binding extends WSDL with the following extension elements:
SOAP 绑定使用以下扩展元素扩展了 WSDL:
<definitions .... >
<binding .... >
<soap:binding style="rpc|document" transport="uri">
<operation .... >
<soap:operation soapAction="uri"? style="rpc|document"?>?
<input>
<soap:body parts="nmtokens"? use="literal|encoded"
encodingStyle="uri-list"? namespace="uri"?>
<soap:header message="qname" part="nmtoken" use="literal|encoded"
encodingStyle="uri-list"? namespace="uri"?>*
<soap:headerfault message="qname" part="nmtoken" use="literal|encoded"
encodingStyle="uri-list"? namespace="uri"?/>*
<soap:header>
</input>
<output>
<soap:body parts="nmtokens"? use="literal|encoded"
encodingStyle="uri-list"? namespace="uri"?>
<soap:header message="qname" part="nmtoken" use="literal|encoded"
encodingStyle="uri-list"? namespace="uri"?>*
<soap:headerfault message="qname" part="nmtoken" use="literal|encoded"
encodingStyle="uri-list"? namespace="uri"?/>*
<soap:header>
</output>
<fault>*
<soap:fault name="nmtoken" use="literal|encoded"
encodingStyle="uri-list"? namespace="uri"?>
</fault>
</operation>
</binding>
<port .... >
<soap:address location="uri"/>
</port>
</definitions>

