CTOCIO IT专家网

天极传媒 比特网 | 天极网 | IT专家网 | IT商网 | 52PK游戏网 | 手机天极 | IT分众 |
IT专家网搜索

您现在的位置: IT专家网 > Web服务子站 > 技巧

使用WS-I的wsi:swaRef XML类型的附件

作者: Russell Butek ,  出处:developerWorks 中国 , 责任编辑: 叶江, 
2006-09-26 14:00
  本文介绍如何使用 Web 服务互操作性组织 (Web Services Interoperability Organization) 定义的 XML 附件类型:wsi:swaRef。

  本文介绍如何使用 Web 服务互操作性组织 (Web Services Interoperability Organization) 定义的 XML 附件类型:wsi:swaRef。

  引言

  IBM developerWorks 发布了多篇介绍各种发送 Web 服务附件的方法的文章(相关链接请参阅参考资料)。本文介绍了另一种机制,即 Web 服务互操作性 (WS-I) 组织的带附件的 SOAP参考类型:wsi:swaRef。

  为什么使用 wsi:swaRef?

  因为没有针对附件的 XML 类型,因此 WS-I 创建了一个这样的 XML 类型。WSDL 规范包含一个附件定义,但是由于各种原因,该定义存在以下不足:

  •   附件在接口中不可见
  •   只有消息部分才能包含附件
  •   附件与 document/literal 包装的内容不能很好地融合

  附件在接口中不可见

  附件是在 SOAP 中定义的,而 WSDL 规范将 SOAP 附件映射到 WSDL 绑定。这就意味着 WSDL 文档的接口 部分(portType、messages 和 types)并不能识别附件。

  以清单 1 中所示的代码为例。其中的代码摘自“Web 服务编程技巧和诀窍: 使用 JAX-RPC 来传递 SOAP 附件 ”一文(请参阅参考资料)。如果您暂时忽略绑定,而只看 WSDL 的接口,会在其中看到两个操作,即 sendImage 和 sendOctet。每个操作都有一个 hexBinary 输入。JAX-RPC 将 hexBinary 映射到一个 Java byte[]。仅通过该信息就可以合理地猜到,此 WSDL 接口将映射到一个包含两个方法的 Java 接口,其中每个方法都有一个 byte[] 参数。猜的没错,的确如此,但 MIME 类型例外。对于 MIME 类型,必须检查绑定,才能确定真实的参数类型。您将在绑定中看到操作的输入实际上是 MIME 内容类型——图像/jpeg 和应用程序/八进制流——而不是 hexBinary。JAX-RPC 会将其分别映射到 java.awt.Image 和 javax.activation.DataHandler。

  对于附件,仅根据 WSDL 接口并不足以确定 Java 接口。这非常不方便。接口与实现之间的界线因此变得模糊了。

  清单 1. 带附件的 WSDL——WS-I 的 wsi:swaRef 出现之前

<definitions
    xmlns="http://schemas.xmlsoap.org/wsdl/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
    targetNamespace="urn:attachment.tip"
    xmlns:tns="urn:attachment.tip">
  <message name="empty"/>
  <message name="imageMsg">
    <part name="image" type="xsd:hexBinary"/>
  </message>
  <message name="octetMsg">
    <part name="octet" type="xsd:hexBinary"/>
  </message>

  <portType name="AttachmentTip">
    <operation name="sendImage">
      <input message="tns:imageMsg"/>
      <output message="tns:empty"/>
    </operation>
    <operation name="sendOctet">
      <input message="tns:octetMsg"/>
      <output message="tns:empty"/>
    </operation>
  </portType>

  <binding name="AttachmentBinding" type="tns:AttachmentTip">
    <soap:binding style="rpc"
                  transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="sendImage">
      <soap:operation soapAction=""/>
      <input>
        <mime:multipartRelated>
          <mime:part>
            <soap:body use="literal"/>
          </mime:part>
          <mime:part>
            <mime:content part="image" type="image/jpeg"/>
          </mime:part>
        </mime:multipartRelated>
      </input>
      <output>
        <soap:body use="literal"/>
      </output>
    </operation>
    <operation name="sendOctet">
      <soap:operation soapAction=""/>
      <input>
        <mime:multipartRelated>
          <mime:part>
            <soap:body use="literal"/>
          </mime:part>
          <mime:part>
            <mime:content part="octet" type="application/octet-stream"/>
          </mime:part>
        </mime:multipartRelated>
      </input>
      <output>
        <soap:body use="literal"/>
      </output>
    </operation>
  </binding>

  <service name="AttachmentService">
    <port name="AttachmentTip" binding="tns:AttachmentBinding">
      <soap:address
          location="http://localhost:9080/attachment/services/AttachmentTip"/>
    </port>
  </service>

</definitions>

共3页。 1 2 3 :

网友评论

笔名 
请您注意:遵守国家有关法律、法规,尊重网上道德,承担一切因您的行为而直接或间接引起的法律责任。    IT专家网友拥有管理笔名和留言的一切权利。
  • 周排行榜
  • 月排行榜

邮件订阅

       

该文章的读者还阅读了

天极服务 | 关于我们 | 网站律师 | 加入我们 | 联系我们 | 广告业务 | 友情链接 | 我要挑错
All Rights Reserved, Copyright 2004-2008, Ctocio.com.cn
渝ICP证B2-20030003号 如有意见请与我们联系 powered by 天极内容管理平台CMS4i