搜索

第 6 章 使用 SOAP 1.1 消息

download PDF

摘要

Apache CXF 提供了一个工具来生成 SOAP 1.1 绑定,该绑定不使用任何 SOAP 标头。但是,您可以使用任何文本或 XML 编辑器将 SOAP 标头添加到绑定中。

6.1. 添加 SOAP 1.1 绑定

使用 wsdl2soap

要使用 wsdl2soap 生成一个 SOAP 1.1 绑定,请使用以下命令: wsdl2soap-iport-type-name-bbinding-name-doutput-directory-ooutput-file-nsoap-body-namespace-style (document/rpc)-use (literal/encoded)-v-verbose-quietwsdlurl

注意

要使用 wsdl2soap,您需要下载 Apache CXF 发行版。

该命令有以下选项:

选项解释

-i port-type-name

指定生成绑定的 portType 元素。

wsdlurl

包含 portType 元素定义的 WSDL 文件的路径和名称。

该工具有以下可选参数:

选项解释

-b binding-name

指定生成的 SOAP 绑定的名称。

-d output-directory

指定要放置生成的 WSDL 文件的目录。

-o output-file

指定生成的 WSDL 文件的名称。

-n soap-body-namespace

指定 RPC 样式时的 SOAP 正文命名空间。

-style (document/rpc)

指定要在 SOAP 绑定中使用的编码样式(文档或 RPC)。默认为 document。

-use (字面/编码)

指定在 SOAP 绑定中使用的绑定使用(编码或字面)。默认值为 literal。

-v

显示工具的版本号。

-verbose

在代码生成过程中显示注释。

-quiet

在代码生成过程中抑制注释。

需要 -iport-type-namewsdlurl 参数。如果指定了 -style rpc 参数,则还需要 -nsoap-body-namspace 参数。所有其他参数都是可选的,可按任何顺序列出。

重要

wsdl2soap 不支持生成 文档/编码的 SOAP 绑定。

Example

如果您的系统有一个需要顺序的接口,并提供单个操作来处理其在 WSDL 片段中定义的顺序,类似于 例 6.1 “排序系统接口” 中显示的顺序。

例 6.1. 排序系统接口

<?xml version="1.0" encoding="UTF-8"?>
<definitions name="widgetOrderForm.wsdl"
    targetNamespace="http://widgetVendor.com/widgetOrderForm"
    xmlns="http://schemas.xmlsoap.org/wsdl/"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:tns="http://widgetVendor.com/widgetOrderForm"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsd1="http://widgetVendor.com/types/widgetTypes"
    xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">

<message name="widgetOrder">
  <part name="numOrdered" type="xsd:int"/>
</message>
<message name="widgetOrderBill">
  <part name="price" type="xsd:float"/>
</message>
<message name="badSize">
  <part name="numInventory" type="xsd:int"/>
</message>

<portType name="orderWidgets">
  <operation name="placeWidgetOrder">
    <input message="tns:widgetOrder" name="order"/>
    <output message="tns:widgetOrderBill" name="bill"/>
    <fault message="tns:badSize" name="sizeFault"/>
  </operation>
</portType>
...
</definitions>

orderWidget 生成的 SOAP 绑定显示在 例 6.2 “用于 orderWidget 的SOAP 1.1 Binding” 中。

例 6.2. 用于 orderWidget 的SOAP 1.1 Binding

<binding name="orderWidgetsBinding" type="tns:orderWidgets">
  <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="placeWidgetOrder">
      <soap:operation soapAction="" style="document"/>
      <input name="order">
        <soap:body use="literal"/>
      </input>
      <output name="bill">
        <soap:body use="literal"/>
      </output>
      <fault name="sizeFault">
        <soap:body use="literal"/>
      </fault>
  </operation>
</binding>

此绑定指定消息使用 文档/字面 消息样式发送。

Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.