Web service中的RPC和document选择

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.

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.


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.

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.

document的的body可以包含多个子元素,而rpc格式的最多只能有一个子元素,参数包含在该子元素下。实际上大多数的soap信封的格式从外表看来都是一样的。至于选择哪种方式看个人口味
rpc
<SOAP:Body>
  <rpc-operation>
   <message-part-1><!-- mapped to a parameter-- >
   <message-part-2><!-- mapped to a parameter-- >
  </rpc-operation>
</SOAP:Body>
document
<SOAP:Body>
  <message-part-1> ...
  <message-part-2> ...
</SOAP:Body>


然而, 以目前來說, 不管是.NET 或 JAVA, 並沒有將這兩種 operation 的實作方式明顯
的區分, 一搬來說, 不管是 RPC Operation 亦或是 Document Operation, 後端都是以
一個 Method 來實作, 本質上都是 RPC.

你可能感兴趣的:(web Service)