Currently, the relevant standards for Web Services are WSDL [Web Service Description Language], a standard language similar to XML schema, it is used to describe in detail the web service and soap [Simple Object Access Protocol]. The actual communication protocol used by the Web Service is soap. The WSDL Binding style is composed of two attributes: style and use; style can be rpc/document, and use can be encoded/literal. The following describes the meanings of the four nouns:
RPCStyle
The RPC style specifies that the <soap: Body> element contains the name of a web method to be called (wrapper element (encapsulation element )). This element records each parameter of the method and the return value in sequence.
Document Style
If it is a document style, there is no wrapper element like in the RPC style. Instead, message fragments appear directly under the <soap: Body> element. There is no soap formatting rule that specifies what the <soap: Body> element can contain. It contains an XML document that is consistent between the sender and receiver.
Encoded Encoding
If the value of use is "encoded", each message segment usesTypeAttribute to reference the abstract type. ByEncodingstyleThe encoding style specified by the attribute. You can use these abstract types to generate specific messages. The most common soap encoding style is a set of serialization rules defined in soap1.1, which describes how objects, structures, arrays, and graphic objects should be serialized. Generally, the use of soap encoding in applications focuses on remote process calls and later RPC message styles.
Literal text?
If the value of use is "literal", useElementAttribute (for simple snippets) orTypeAttribute (for composite fragments) to reference a specific architecture. For example, data is serialized Based on the specified architecture, which is usually expressed using the W3C XML architecture.
Four binding models are formed based on different combinations. In addition, it is also common to use document to simulate RPC-style packaging combinations;
- RPC/encoded
- RPC/literal
- Document/encoded
- Document/literal
- Document/literal wrapped
For the above five combination methods, since document/encoded is not supported by the existing platform and is rarely used in practice, this combination is not discussed here; for the remaining four combinations, we use a table and an instance to compare their advantages and disadvantages;
Binding type |
Advantage/disadvantage |
RPC/encoded |
Advantages:
- The definition of the WSDL File follows an intuitive and well-known communication mode for remote process calls.
- The operation name is displayed in the message, so the receiver can easily assign the message to it.
- If you are using data graphics or polymorphism in your service, this is the only style that can be used.
Disadvantages:
- The Type encoding information contained in a SOAP message is like xsi: TYPE = "XSD: int", which is an overhead.
- It is usually difficult to verify the SOAP message because it is not described in the WSDL shcema.
- The RPC style causes a close coupling between the service provider and the customer. Any changes to the interface will interrupt the connection between the service and the customer.
- It is not supported by the WSI consistency standard.
|
RPC/literal |
Advantages:
- The WSDL definition is still as simple and straightforward as the RPC/encoded style.
- The operation name still appears in the SOAP message.
- The Type encoding is excluded from the message, thus improving the throughput performance.
Disadvantages:
- The service is still tightly coupled with the customer.
- It is still difficult to use soap messages to verify transmitted data.
- It is not supported by the WSI consistency standard.
|
Document/litaral |
Advantages:
- There is no type encoding information in the SOAP message.
- You can always use any XML validators to verify messages. Everything in the soap body is defined in the schema.
- When the document style is used, the rules are not so strict, and the interface is not damaged when the XML schema is enhanced or changed.
- If a special sequence is used for multi-process calling, the document style can maintain the state of the application.
- The document style is more suitable for asynchronous processing.
- Many document-messaging services can select one of the two Processing Methods of the document Dom and sax, and the result is to minimize the processing in the memory.
Disadvantages:
- The definition of WSDL becomes more complex.
- If the operation name in a SOAP message is absent and the name is absent, it becomes difficult or impossible to assign the message to it.
|
Document/literalwrapped |
Advantages:
- It includes the advantages of all document/literal styles.
- The operation name appears in the SOAP message.
Disadvantages:
- Even if the definition of WSDL becomes more complex, there are still many disadvantages.
- If you reload operations in the Web service, you cannot use this style.
|
Assume that the method of WS to be called is public void mymethod (int x). The WSDL/soap fragments generated by various binding styles are as follows:
Binding type |
WSDL |
Soap |
RPC/encoded |
<message name="myMethodRequest"><part name="x" type="xsd:int" /></message><message name="empty" /><portType name="PT"><operation name="myMethod"><input message="myMethodRequest" /><output message="empty" /></operation></portType><binding><!-- RPC/encoded. --></binding> |
<soap:envelope><soap:body><myMethod><x xsi:type="xsd:int">5</x></myMethod></soap:body></soap:envelope> |
RPC/literal |
<message name="myMethodRequest"><part name="x" type="xsd:int" /></message><message name="empty" /><portType name="PT"><operation name="myMethod"><input message="myMethodRequest" /><output message="empty" /></operation></portType><binding><!-- RPC/literal. --></binding> |
<soap:envelope><soap:body><myMethod><x>5</x></myMethod></soap:body></soap:envelope> |
Document/litaral |
<types><schema><element name="xElement" type="xsd:int" /></schema></types><message name="myMethodRequest"><part name="x" element="xElement" /></message><message name="empty" /><portType name="PT"><operation name="myMethod"><input message="myMethodRequest" /><output message="empty" /></operation></portType><binding><!-- document/literal. --></binding>
|
<soap:envelope><soap:body><xElement>5</xElement></soap:body></soap:envelope> |
Document/literal wrapped |
<types><schema><element name="myMethod" /><complexType><sequence><element name="x" type="xsd:int" /></sequence></complexType></element></schema></types><message name="myMethodRequest"><part name="parameters" element="myMethod" /></message><message name="empty" /><portType name="PT"><operation name="myMethod"><input message="myMethodRequest" /><output message="empty" /></operation></portType><binding><!-- document/literal. --></binding>
|
<soap:envelope><soap:body><myMethod><x>5</x></myMethod></soap:body></soap:envelope> |