20 Nov 2004
Binding Style and Use
A web service is usually described by a WSDL (Web Services Description Language) document. In this document, the supported web service operations and messages are described abstractly and then bound to a concrete network protocol and message format. A typical WSDL document consists of the following elements: "types," "message," and "portType" for the abstract definitions; "binding" and "service" for the concrete specification. All of these elements are wrapped inside a "definitions" element.
通常情况下,web服务是由一个wadl文件来描述的的。在这个文件中,抽象的描述所支持的web服务操作和消息,然后关联到一个具体的网络歇息和消息格式。典型的wsdl文件由这个几个元素组成:tyoes,message.porttype用来描述抽象的定义;biding和service指定具体的实现。所有的这些元素包装在definitions元素中。
In the context of RPC and document style, it is the binding element that we need to take a closer look at. A WSDL binding describes how the service is bound to a messaging protocol, either HTTP GET/POST, MIME, or SOAP. In practice, SOAP is the most universally used protocol; it is SOAP that the RPC/document distinction refers to. Usually HTTP(S) is used as transport protocol for the SOAP message – "SOAP over HTTP(S)."
在binding元素中,rpc和document是最值得我们关注的元素。wsdl 的 binding描述了如何将service关联到消息协议;这些消息协议是http,mime,soap中的任意一种。不过,实际中,soap是最常用的协议;rpc和document的区别也是在soap的下的区别(it is SOAP thatthe RPC/document distinction refers to)。通常http(s)是传输soap消息的协议。
The <wsdl:binding> element of the WSDL contains a pair of parameters that influence the form of the resulting SOAP messages: binding style (RPC or document) and use (encoded or literal). See how style and use are defined in the WSDL fragment below:
<wsdl:binding>元素包含一对参数,style(rpc|document)和use(encoded|literal),他俩会影响到soap消息的格式.他们的使用方式如下
<wsdl:binding name="Config1Binding" type="prt0:CreditLimitLocalWebServiceVi_Document">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
<wsdl:operation name="creditLimitCheck">
<soap:operation soapAction="" />
<wsdl:input>
<soap:body use="literal" parts="parameters" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
The "Style" Attribute
WSDL 1.1 specifies the style of the binding as either RPC or document. This choice corresponds to how the SOAP payload - i.e., how the contents of the <soap:Body> element - can be structured. Here are some details of how each style affects the contents of <soap:Body>:
wsdl1.1要求binding的style要么是rpc要么是doucment。这个选择与如何组织soap的负荷相关。下面是分别他们如何影响<soap:body>内容的细节。
Document: the content of <soap:Body> is specified by XML Schema defined in the <wsdl:type> section. It does not need to follow specific SOAP conventions. In short, the SOAP message is sent as one "document" in the <soap:Body> element without additional formatting rules having to be considered. Document style is the default choice.
document:<soap:body>的内容由定义在<wsdl:type>中的xml模式指定。他不需要遵循特定的soap规范。简言之,soap消息是通过<soap:body>中的document发送出去,而没有额外的要遵循的格式规则。document style是一种默认的选择。
RPC: The structure of an RPC style <soap:Body> element needs to comply with the rules specified in detail in Section 7 of the SOAP 1.1 specification. According to these rules, <soap:Body> may contain only one element that is named after the operation, and all parameters must be represented as sub-elements of this wrapper element.
rpc: <soap:body>元素的结构需要遵循特定的规则(soap1.1规范第7部分有细节)。根据这些规则,<soap:body>可以包含唯一一个元素,这个元素用方法命名,所有的参数都必须写成这个元素的子元素。
As a consequence of the freedom of choice that the document style offers, the SOAP messages conforming to a document style WSDL may look exactly the same as the RPC equivalent.
因为可以自由的选择哪种消息格式,遵循document格式的soap消息看上去很像rpc格式。
The decisive question now is: What are the consequences of choosing one option or another? Why choose RPC over document, or document over RPC? In many cases, the SOAP messages generated from either RPC or document style WSDLs look exactly the same - so why offer the choice at all? The reason may be found in the history of the SOAP standard.
现在,决定性的问题是:选择其中任意一个选项后的结果是什么样?为何要选择rpc或者document?很多情况下,选择他们后,soap消息的格式看起来很相像,那么为什么还要提供这种选择呢?原因要从soap标准化的历程中寻找
SOAP has its roots in synchronous remote procedure calls over HTTP and the appearance of the document accordingly followed these conventions. Later, it was seen as a simplification to use arbitrary XML in the SOAP body without adhering to conventions. This preference is reflected in the document style WSDL documents. So far, both options are represented in the WSDL specification and the choice of one or the other is mainly a question of personal taste since most SOAP clients today accept both versions.
SOAP归根与透过HTTP并且遵循这些公约的文档的远程过程调用。后来在soap body用xml格式而不遵循那些公约看起来更为简单。这种偏向直接反映在document格式的WSDL文档。现在这两种选项都出现在WSDL中,其选择权主要还是归结与客户的口味。
The "Use" Attribute
The use attribute specifies the encoding rules of the SOAP message. This is also done within the <wsdl:binding> element, as seen in the example above. The value can be encoded or literal. It refers to the serialization rules followed by the SOAP client and the SOAP server to interpret the contents of the <Body> element in the SOAP payload.
在<wsdl:binding>元素中指定的Use属性,指定SOAP消息的编码规则。消息体的值可以是有编码的也可以是字面上(无编码),这个取决于客户端和服务器在解释body内容的序列化规则。
use="literal" means that the type definitions literally follow an XML schema definition.
use="literal" 指的是类型定义严格按照xml schema定义。
use="encoded" refers to the representation of application data in XML, usually according to the SOAP encoding rules of the SOAP 1.1 specification. The rules to encode and interpret a SOAP body are in a URL specified by the encodingStyle attribute. Encoded is the appropriate choice where non-treelike structures are concerned, because all others can be perfectly described in XML Schema.
use="encoded" 参考xml中已有的应用数据,通常指的是soap1.1规范中的soap编码规则。编码并解码一个soap body 是通过一个encodingStyle 属性的url值指定的。Encode一般是应用在 非树形结构体的应用中,因为其他的可以用schema很好的描述。
The combination of the style and use attributes leads to four possible style/use pairs:
两个属性的组合导致了有4种搭配
RPC/encoded
RPC/literal
document/encoded(少用)
document/literal
Some of these combinations are rarely used in practice, such as document/encoded. In general, the literal use is gaining importance, and as far as RPC/encoded is concerned, the Web Services Interoperability Organization (WS-I) in its Basic Profile Version 1.0a of August 2003 ruled out the use of SOAP encoding with web services. Document/literal and RPC/literal will be the only allowed style/use combinations in the future.
有些组合很少使用,比如document/encoded。一般literal非常重要,例如:在WS-I的2003年基本轮廓1.0a版本中RPC/encoded 就被提到了。Document/literal 和RPC/literal 仅仅是在特性上提供支持而已
Binding Style and Use
A web service is usually described by a WSDL (Web Services Description Language) document. In this document, the supported web service operations and messages are described abstractly and then bound to a concrete network protocol and message format. A typical WSDL document consists of the following elements: "types," "message," and "portType" for the abstract definitions; "binding" and "service" for the concrete specification. All of these elements are wrapped inside a "definitions" element.
通常情况下,web服务是由一个wadl文件来描述的的。在这个文件中,抽象的描述所支持的web服务操作和消息,然后关联到一个具体的网络歇息和消息格式。典型的wsdl文件由这个几个元素组成:tyoes,message.porttype用来描述抽象的定义;biding和service指定具体的实现。所有的这些元素包装在definitions元素中。
In the context of RPC and document style, it is the binding element that we need to take a closer look at. A WSDL binding describes how the service is bound to a messaging protocol, either HTTP GET/POST, MIME, or SOAP. In practice, SOAP is the most universally used protocol; it is SOAP that the RPC/document distinction refers to. Usually HTTP(S) is used as transport protocol for the SOAP message – "SOAP over HTTP(S)."
在binding元素中,rpc和document是最值得我们关注的元素。wsdl 的 binding描述了如何将service关联到消息协议;这些消息协议是http,mime,soap中的任意一种。不过,实际中,soap是最常用的协议;rpc和document的区别也是在soap的下的区别(it is SOAP thatthe RPC/document distinction refers to)。通常http(s)是传输soap消息的协议。
The <wsdl:binding> element of the WSDL contains a pair of parameters that influence the form of the resulting SOAP messages: binding style (RPC or document) and use (encoded or literal). See how style and use are defined in the WSDL fragment below:
<wsdl:binding>元素包含一对参数,style(rpc|document)和use(encoded|literal),他俩会影响到soap消息的格式.他们的使用方式如下
<wsdl:binding name="Config1Binding" type="prt0:CreditLimitLocalWebServiceVi_Document">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
<wsdl:operation name="creditLimitCheck">
<soap:operation soapAction="" />
<wsdl:input>
<soap:body use="literal" parts="parameters" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
The "Style" Attribute
WSDL 1.1 specifies the style of the binding as either RPC or document. This choice corresponds to how the SOAP payload - i.e., how the contents of the <soap:Body> element - can be structured. Here are some details of how each style affects the contents of <soap:Body>:
wsdl1.1要求binding的style要么是rpc要么是doucment。这个选择与如何组织soap的负荷相关。下面是分别他们如何影响<soap:body>内容的细节。
Document: the content of <soap:Body> is specified by XML Schema defined in the <wsdl:type> section. It does not need to follow specific SOAP conventions. In short, the SOAP message is sent as one "document" in the <soap:Body> element without additional formatting rules having to be considered. Document style is the default choice.
document:<soap:body>的内容由定义在<wsdl:type>中的xml模式指定。他不需要遵循特定的soap规范。简言之,soap消息是通过<soap:body>中的document发送出去,而没有额外的要遵循的格式规则。document style是一种默认的选择。
RPC: The structure of an RPC style <soap:Body> element needs to comply with the rules specified in detail in Section 7 of the SOAP 1.1 specification. According to these rules, <soap:Body> may contain only one element that is named after the operation, and all parameters must be represented as sub-elements of this wrapper element.
rpc: <soap:body>元素的结构需要遵循特定的规则(soap1.1规范第7部分有细节)。根据这些规则,<soap:body>可以包含唯一一个元素,这个元素用方法命名,所有的参数都必须写成这个元素的子元素。
As a consequence of the freedom of choice that the document style offers, the SOAP messages conforming to a document style WSDL may look exactly the same as the RPC equivalent.
因为可以自由的选择哪种消息格式,遵循document格式的soap消息看上去很像rpc格式。
The decisive question now is: What are the consequences of choosing one option or another? Why choose RPC over document, or document over RPC? In many cases, the SOAP messages generated from either RPC or document style WSDLs look exactly the same - so why offer the choice at all? The reason may be found in the history of the SOAP standard.
现在,决定性的问题是:选择其中任意一个选项后的结果是什么样?为何要选择rpc或者document?很多情况下,选择他们后,soap消息的格式看起来很相像,那么为什么还要提供这种选择呢?原因要从soap标准化的历程中寻找
SOAP has its roots in synchronous remote procedure calls over HTTP and the appearance of the document accordingly followed these conventions. Later, it was seen as a simplification to use arbitrary XML in the SOAP body without adhering to conventions. This preference is reflected in the document style WSDL documents. So far, both options are represented in the WSDL specification and the choice of one or the other is mainly a question of personal taste since most SOAP clients today accept both versions.
SOAP归根与透过HTTP并且遵循这些公约的文档的远程过程调用。后来在soap body用xml格式而不遵循那些公约看起来更为简单。这种偏向直接反映在document格式的WSDL文档。现在这两种选项都出现在WSDL中,其选择权主要还是归结与客户的口味。
The "Use" Attribute
The use attribute specifies the encoding rules of the SOAP message. This is also done within the <wsdl:binding> element, as seen in the example above. The value can be encoded or literal. It refers to the serialization rules followed by the SOAP client and the SOAP server to interpret the contents of the <Body> element in the SOAP payload.
在<wsdl:binding>元素中指定的Use属性,指定SOAP消息的编码规则。消息体的值可以是有编码的也可以是字面上(无编码),这个取决于客户端和服务器在解释body内容的序列化规则。
use="literal" means that the type definitions literally follow an XML schema definition.
use="literal" 指的是类型定义严格按照xml schema定义。
use="encoded" refers to the representation of application data in XML, usually according to the SOAP encoding rules of the SOAP 1.1 specification. The rules to encode and interpret a SOAP body are in a URL specified by the encodingStyle attribute. Encoded is the appropriate choice where non-treelike structures are concerned, because all others can be perfectly described in XML Schema.
use="encoded" 参考xml中已有的应用数据,通常指的是soap1.1规范中的soap编码规则。编码并解码一个soap body 是通过一个encodingStyle 属性的url值指定的。Encode一般是应用在 非树形结构体的应用中,因为其他的可以用schema很好的描述。
The combination of the style and use attributes leads to four possible style/use pairs:
两个属性的组合导致了有4种搭配
RPC/encoded
RPC/literal
document/encoded(少用)
document/literal
Some of these combinations are rarely used in practice, such as document/encoded. In general, the literal use is gaining importance, and as far as RPC/encoded is concerned, the Web Services Interoperability Organization (WS-I) in its Basic Profile Version 1.0a of August 2003 ruled out the use of SOAP encoding with web services. Document/literal and RPC/literal will be the only allowed style/use combinations in the future.
有些组合很少使用,比如document/encoded。一般literal非常重要,例如:在WS-I的2003年基本轮廓1.0a版本中RPC/encoded 就被提到了。Document/literal 和RPC/literal 仅仅是在特性上提供支持而已