了解WSDL中的style和use

1.   Styleuse的组合

<o:p> </o:p>

use属性可以为literalencodedstyle可以为rpcdocument,我们来对五种类型的style/use决定的binding作一比较,分别是rpc/literal, document/literal none-wrapper, document/literal with wrapper, rpc/encoded, 以及document/encoded<o:p></o:p>

从生成soap消息的角度看,rpcdocument的差别在于方法的操作名是否出现在生成的Soap消息中,encodedliteral编码方式的差别在于参数类型是否出现在生成的Soap消息中。

这样rpc/encoded能够完整地表示一个方法调用,但缺点是性能很差,而且不能校验Soap消息的有效性。

rpc/literal不对参数类型进行编码,但仍然无法对Soap消息进行校验。Document/encoded没有意义,因为没有方法名,对参数类型编码没有什么意义。

document/literal none-wrapper无法生成操作名,适用于完整的文档作为参数传递给方法的场景。

document/literal with wrapper应该是目前使用最多的方式,在xfire中也是默认配置。

2.   示例

<o:p> </o:p>

2.1. Java方法

<o:p> </o:p>

public void myMethod(int x);<o:p></o:p>

2.2. Rpc/encoded

<o:p> </o:p>

Rpc风格的特点是message元素的每一个part都必须用type属性定义。encoded用来指明一个类型编码模型,不依赖于XML Schema

清单 2. 用于 myMethod RPC/编码的 WSDL <o:p></o:p>

<message name="myMethodRequest"><o:p></o:p>

    <part name="x" type="xsd:int"/><o:p></o:p>

</message><o:p></o:p>

<message name="empty"/><o:p></o:p>

<portType name="PT"><o:p></o:p>

    <operation name="myMethod"><o:p></o:p>

        <input message="myMethodRequest"/><o:p></o:p>

        <output message="empty"/><o:p></o:p>

    </operation><o:p></o:p>

</portType><o:p></o:p>

<binding .../>  <o:p></o:p>

<!-- I won't bother with the details, just assume it's RPC/encoded. --><o:p></o:p>

<o:p> </o:p>

现在用“5”作为参数 x 的值来调用此方法。我们将发送一个与 清单3类似的 SOAP 消息。

清单 3. 用于 myMethod RPC/编码的 SOAP 消息 <o:p></o:p>

<soap:envelope><o:p></o:p>

    <soap:body><o:p></o:p>

        <myMethod><o:p></o:p>

            <x xsi:type="xsd:int">5</x><o:p></o:p>

        </myMethod><o:p></o:p>

    </soap:body><o:p></o:p>

</soap:envelope><o:p></o:p>

<o:p> </o:p>

2.3. RPC/文字

<o:p> </o:p>

用于我们的方法的 RPC/文字的 WSDL 看起来与 RPC/编码的 WSDL 几乎一样。只是绑定的用法由 编码改为 文字。仅此而已。

4. 用于 myMethod RPC/文字的 WSDL<o:p></o:p>

<message name="myMethodRequest"><o:p></o:p>

    <part name="x" type="xsd:int"/><o:p></o:p>

</message><o:p></o:p>

<message name="empty"/><o:p></o:p>

<portType name="PT"><o:p></o:p>

    <operation name="myMethod"><o:p></o:p>

        <input message="myMethodRequest"/><o:p></o:p>

        <output message="empty"/><o:p></o:p>

    </operation><o:p></o:p>

</portType><o:p></o:p>

<binding .../>  <o:p></o:p>

<!-- I won't bother with the details, just assume it's RPC/<o:p></o:p>

        literal. --><o:p></o:p>

      <o:p></o:p>

<o:p> </o:p>

RPC/文字的 SOAP 消息去掉了类型编码。

清单 5. 用于 myMethod RPC/文字的 SOAP 消息<o:p></o:p>

<soap:envelope><o:p></o:p>

    <soap:body><o:p></o:p>

        <myMethod><o:p></o:p>

            <x>5</x><o:p></o:p>

        </myMethod><o:p></o:p>

    </soap:body><o:p></o:p>

</soap:envelope><o:p></o:p>

<o:p> </o:p>

2.4. document/literal

<o:p> </o:p>

document/literal的主要特点是message元素的每一个part都使用element属性引用一个types下面定义的schema元素。<o:p></o:p>

清单6. 用于 myMethod 的文档/文字的 WSDL<o:p></o:p>

<types><o:p></o:p>

    <schema><o:p></o:p>

        <element name="xElement" type="xsd:int"/><o:p></o:p>

    </schema><o:p></o:p>

</types><o:p></o:p>

<message name="myMethodRequest"><o:p></o:p>

    <part name="x" element="xElement"/><o:p></o:p>

</message><o:p></o:p>

<message name="empty"/><o:p></o:p>

<portType name="PT"><o:p></o:p>

    <operation name="myMethod"><o:p></o:p>

        <input message="myMethodRequest"/><o:p></o:p>

        <output message="empty"/><o:p></o:p>

    </operation><o:p></o:p>

</portType><o:p></o:p>

<binding .../>  <o:p></o:p>

<!-- I won't bother with the details, just assume it's <o:p></o:p>

        document/literal. --><o:p></o:p>

      <o:p></o:p>

清单7. 用于 myMethod 的文档/文字的 SOAP 消息<o:p></o:p>

<soap:envelope><o:p></o:p>

    <soap:body><o:p></o:p>

        <xElement>5</xElement><o:p></o:p>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值