Este conteúdo não está disponível no idioma selecionado.
Chapter 7. Using SOAP 1.2 Messages
Abstract
Apache CXF provides tools to generate a SOAP 1.2 binding which does not use any SOAP headers. You can add SOAP headers to your binding using any text or XML editor.
7.1. Adding a SOAP 1.2 Binding to a WSDL Document Copiar o linkLink copiado para a área de transferência!
Using wsdl2soap Copiar o linkLink copiado para a área de transferência!
To use wsdl2soap you will need to download the Apache CXF distribution.
To generate a SOAP 1.2 binding using wsdl2soap use the following command: wsdl2soap-iport-type-name-bbinding-name-soap12-doutput-directory-ooutput-file-nsoap-body-namespace-style (document/rpc)-use (literal/encoded)-v-verbose-quietwsdlurl The tool has the following required arguments:
| Option | Interpretation |
|---|---|
|
|
Specifies the |
|
| Specifies that the generated binding uses SOAP 1.2. |
| wsdlurl |
The path and name of the WSDL file containing the |
The tool has the following optional arguments:
| Option | Interpretation |
|---|---|
|
| Specifies the name of the generated SOAP binding. |
|
| Specifies that the generated binding will use SOAP 1.2. |
|
| Specifies the directory to place the generated WSDL file. |
|
| Specifies the name of the generated WSDL file. |
|
| Specifies the SOAP body namespace when the style is RPC. |
|
| Specifies the encoding style (document or RPC) to use in the SOAP binding. The default is document. |
|
| Specifies the binding use (encoded or literal) to use in the SOAP binding. The default is literal. |
|
| Displays the version number for the tool. |
|
| Displays comments during the code generation process. |
|
| Suppresses comments during the code generation process. |
The -i port-type-name and wsdlurl arguments are required. If the -style rpc argument is specified, the -n soap-body-namspace argument is also required. All other arguments are optional and can be listed in any order.
wsdl2soap does not support the generation of document/encoded SOAP 1.2 bindings.
Example Copiar o linkLink copiado para a área de transferência!
If your system has an interface that takes orders and offers a single operation to process the orders it is defined in a WSDL fragment similar to the one shown in Example 7.1, “Ordering System Interface”.
Example 7.1. Ordering System Interface
The SOAP binding generated for orderWidgets is shown in Example 7.2, “SOAP 1.2 Binding for orderWidgets”.
Example 7.2. SOAP 1.2 Binding for orderWidgets
This binding specifies that messages are sent using the document/literal message style.
7.2. Adding Headers to a SOAP 1.2 Message Copiar o linkLink copiado para a área de transferência!
Overview Copiar o linkLink copiado para a área de transferência!
SOAP message headers are defined by adding soap12:header elements to your SOAP 1.2 message. The soap12:header element is an optional child of the input, output, and fault elements of the binding. The SOAP header becomes part of the parent message. A SOAP header is defined by specifying a message and a message part. Each SOAP header can only contain one message part, but you can insert as many headers as needed.
Syntax Copiar o linkLink copiado para a área de transferência!
The syntax for defining a SOAP header is shown in Example 7.3, “SOAP Header Syntax”.
Example 7.3. SOAP Header Syntax
The soap12:header element’s attributes are described in Table 7.1, “soap12:header Attributes”.
| Attribute | Description |
|---|---|
| A required attribute specifying the qualified name of the message from which the part being inserted into the header is taken. | |
| A required attribute specifying the name of the message part inserted into the SOAP header. | |
|
Specifies if the message parts are to be encoded using encoding rules. If set to | |
| Specifies the encoding rules used to construct the message. | |
|
Defines the namespace to be assigned to the header element serialized with |
Splitting messages between body and header Copiar o linkLink copiado para a área de transferência!
The message part inserted into the SOAP header can be any valid message part from the contract. It can even be a part from the parent message which is being used as the SOAP body. Because it is unlikely that you would send information twice in the same message, the SOAP 1.2 binding provides a means for specifying the message parts that are inserted into the SOAP body.
The soap12:body element has an optional attribute, parts, that takes a space delimited list of part names. When parts is defined, only the message parts listed are inserted into the body of the SOAP 1.2 message. You can then insert the remaining parts into the message’s header.
When you define a SOAP header using parts of the parent message, Apache CXF automatically fills in the SOAP headers for you.
Example Copiar o linkLink copiado para a área de transferência!
Example 7.4, “SOAP 1.2 Binding with a SOAP Header” shows a modified version of the orderWidgets service shown in Example 7.1, “Ordering System Interface”. This version is modified so that each order has an xsd:base64binary value placed in the header of the request and the response. The header is defined as being the keyVal part from the widgetKey message. In this case you are responsible for adding the application logic to create the header because it is not part of the input or output message.
Example 7.4. SOAP 1.2 Binding with a SOAP Header
You can modify Example 7.4, “SOAP 1.2 Binding with a SOAP Header” so that the header value is a part of the input and output messages, as shown in Example 7.5, “SOAP 1.2 Binding for orderWidgets with a SOAP Header”. In this case keyVal is a part of the input and output messages. In the soap12:body elements the parts attribute specifies that keyVal should not be inserted into the body. However, it is inserted into the header.
Example 7.5. SOAP 1.2 Binding for orderWidgets with a SOAP Header