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/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值