第 6 章 使用 SOAP 1.1 消息
摘要
Apache CXF 提供了一个工具来生成 SOAP 1.1 绑定,该绑定不使用任何 SOAP 标头。但是,您可以使用任何文本或 XML 编辑器将 SOAP 标头添加到绑定中。
6.1. 添加 SOAP 1.1 绑定
使用 wsdl2soap
要使用 wsdl2soap 命令生成 SOAP 1.1 绑定:ws dl2soap-iport-type-name-bbinding-name-doutput-directory-ooutput-file-nsoap-body-namespace-style (document/rpc)-use (literal/encoded)-v-verbose-quietwsdlurl
要使用 wsdl2soap,您需要下载 Apache CXF 分发。
该命令有以下选项:
| 选项 | 解释 |
|---|---|
|
|
指定生成绑定的 |
| wsdlurl |
包含 |
该工具具有以下可选参数:
| 选项 | 解释 |
|---|---|
|
| 指定生成的 SOAP 绑定的名称。 |
|
| 指定要放置所生成的 WSDL 文件的目录。 |
|
| 指定生成的 WSDL 文件的名称。 |
|
| 当样式为 RPC 时,指定 SOAP 正文命名空间。 |
|
| 指定 SOAP 绑定中使用的编码风格(文档或 RPC)。默认为 document。 |
|
| 指定 SOAP 绑定中使用的绑定使用(编码或文字)。默认值为字面值。 |
|
| 显示工具的版本号。 |
|
| 在代码生成过程中显示注释。 |
|
| 在代码生成过程中阻止注释。 |
需要 -iport-type-name 和 wsdlurl 参数。如果指定了 -style rpc 参数,则还需要 -nsoap-body-namspace 参数。所有其他参数都是可选的,可以按任何顺序列出。
wsdl2soap 不支持生成 文档/编码的 SOAP 绑定。
示例
如果您的系统有一个处理订单的接口,并提供单一操作来处理在 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 “orderWidgets的 SOAP 1.1 绑定” 中。
例 6.2. orderWidgets的 SOAP 1.1 绑定
<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>
此绑定指定消息使用 document/literal 消息样式发送。