`

literal和encoded

 
阅读更多
   <binding name="MathSoapHttpBinding" type="y:MathInterface">
      <soap:binding style="document"
             transport="http://schemas.xmlsoap.org/soap/http"/>
      <operation name="Add">
         <soap:operation
                   soapAction="http://example.org/math/#Add"/>
         <input>
            <soap:body use="literal"/>
         </input>
         <output>
            <soap:body use="literal"/>
         </output>
      </operation>
          ...
   </binding>

    The soap:binding element indicates that this is a SOAP 1.1 binding. It also indicates the default style of service (possible values include document or rpc)
along with the required transport protocol (HTTP in this case). The soap:operation element defines the SOAPAction HTTP header value for each operation. And
the soap:body element defines how the message parts appear inside of the SOAP Body element (possible values include literal or encoded). There are other binding-specific details that can be specified this way.

     Using document style in SOAP indicates that the body will contain an XML document, and that the message parts specify the XML elements that will be placed
there. Using rpc style in SOAP indicates that the body will contain an XML representation of a method call and that the message parts represent the parameters to the method.

     The use attribute specifies the encoding that should be used to translate the abstract message parts into a concrete representation. In the case of
'encoded', the abstract definitions are translated into a concrete format by applying the SOAP encoding rules. In the case of 'literal', the abstract type
definitions become the concrete definitions themselves (they're 'literal' definitions). In this case, you can simply inspect the XML Schema type definitions
to determine the concrete message format.


RPC/encoded

WSDL片段:
<message name="myMethodRequest">
    <part name="x" type="xsd:int"/>
    <part name="y" type="xsd:float"/>
</message>
<message name="empty"/>

<portType name="PT">
    <operation name="myMethod">
        <input message="myMethodRequest"/>
        <output message="empty"/>
    </operation>
</portType>

SOAP片段:
<soap:envelope>
    <soap:body>
        <myMethod>
            <x xsi:type="xsd:int">5</x>
            <y xsi:type="xsd:float">5.0</y>
        </myMethod>
    </soap:body>
</soap:envelope>
RPC/literal

WSDL片段:
<message name="myMethodRequest">
    <part name="x" type="xsd:int"/>
    <part name="y" type="xsd:float"/>
</message>
<message name="empty"/>

<portType name="PT">
    <operation name="myMethod">
        <input message="myMethodRequest"/>
        <output message="empty"/>
    </operation>
</portType>

SOAP片段:
<soap:envelope>
    <soap:body>
        <myMethod>
            <x>5</x>
            <y>5.0</y>
        </myMethod>
    </soap:body>
</soap:envelope>


RPC/literal

WSDL片段:
<message name="myMethodRequest">
    <part name="x" type="xsd:int"/>
    <part name="y" type="xsd:float"/>
</message>
<message name="empty"/>

<portType name="PT">
    <operation name="myMethod">
        <input message="myMethodRequest"/>
        <output message="empty"/>
    </operation>
</portType>




SOAP片段:
<soap:envelope>
    <soap:body>
        <myMethod>
            <x>5</x>
            <y>5.0</y>
        </myMethod>
    </soap:body>
</soap:envelope>
Document/literal

WSDL片段:
<types>
    <schema>
        <element name="xElement" type="xsd:int"/>
        <element name="yElement" type="xsd:float"/>
    </schema>
</types>

<message name="myMethodRequest">
    <part name="x" element="xElement"/>
    <part name="y" element="yElement"/>
</message>
<message name="empty"/>

<portType name="PT">
    <operation name="myMethod">
        <input message="myMethodRequest"/>
        <output message="empty"/>
    </operation>
</portType>

SOAP片段:
<soap:envelope>
    <soap:body>
        <xElement>5</xElement>
        <yElement>5.0</yElement>
    </soap:body>
</soap:envelope>


从上面的比较可以看出,literal优于encoded的地方在于可以避免将具体的类型描述(如xsi:type="xsd:int")放在SOAP中,这可以节省不少数据流量;
Document优于RPC的地方在于它将使用Shema确定数据类型便于SOAP格式的验证,但是它却在SOAP消息中丢去了具体的方法标签,不利于服务分发层定位具体的服务实现。
鉴于上面的讨论,我们给出了一种更好的解决办法,即使用
Document/literal wrapped 模式

参考:http://www.ibm.com/developerworks/webservices/library/ws-whichwsdl/
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics