第 7 章 使用 SOAP 1.2 消息
摘要
Apache CXF 提供生成 SOAP 1.2 绑定的工具,该绑定不使用任何 SOAP 标头。您可以使用任何文本或 XML 编辑器将 SOAP 标头添加到绑定中。
7.1. 在 WSDL 文档中添加 SOAP 1.2 绑定
使用 wsdl2soap
要使用 wsdl2soap,您需要下载 Apache CXF 分发。
要使用 wsdl2soap 命令生成 SOAP 1.2 绑定:ws dl2soap-iport-type-name-bbinding-name-soap12-doutput-directory-ooutput-file-nsoap-body-namespace-style (document/rpc)-use (literal/encoded)-name -b binding-quietwdl-quiet wdlurl 工具具有以下参数:
| 选项 | 解释 |
|---|---|
|
|
指定生成绑定的 |
|
| 指定生成的绑定使用 SOAP 1.2。 |
| wsdlurl |
包含 |
该工具具有以下可选参数:
| 选项 | 解释 |
|---|---|
|
| 指定生成的 SOAP 绑定的名称。 |
|
| 指定生成的绑定将使用 SOAP 1.2。 |
|
| 指定要放置所生成的 WSDL 文件的目录。 |
|
| 指定生成的 WSDL 文件的名称。 |
|
| 当样式为 RPC 时,指定 SOAP 正文命名空间。 |
|
| 指定 SOAP 绑定中使用的编码风格(文档或 RPC)。默认为 document。 |
|
| 指定 SOAP 绑定中使用的绑定使用(编码或文字)。默认值为字面值。 |
|
| 显示工具的版本号。 |
|
| 在代码生成过程中显示注释。 |
|
| 在代码生成过程中阻止注释。 |
需要 -i port-type-name 和 wsdlurl 参数。如果指定了 -style rpc 参数,则需要 -n soap-body-namspace 参数。所有其他参数都是可选的,可以按任何顺序列出。
wsdl2soap 不支持生成 文档/编码的 SOAP 1.2 绑定。
示例
如果您的系统有一个处理订单的接口,并提供单一操作来处理在 WSDL 片段中定义的订单,类似于 例 7.1 “排序系统接口” 中显示的订单。
例 7.1. 排序系统接口
<?xml version="1.0" encoding="UTF-8"?>
<definitions name="widgetOrderForm.wsdl"
targetNamespace="http://widgetVendor.com/widgetOrderForm"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
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 绑定显示在 例 7.2 “orderWidgets 的 SOAP 1.2 绑定” 中。
例 7.2. orderWidgets 的 SOAP 1.2 绑定
<binding name="orderWidgetsBinding" type="tns:orderWidgets">
<soap12:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="placeWidgetOrder">
<soap12:operation soapAction="" style="document"/>
<input name="order">
<soap12:body use="literal"/>
</input>
<output name="bill">
<wsoap12:body use="literal"/>
</output>
<fault name="sizeFault">
<soap12:body use="literal"/>
</fault>
</operation>
</binding>
此绑定指定消息使用 document/literal 消息样式发送。