If you are using a SOAP binding for your service, you can use JAX-WS annotations to specify a number of the bindings properties. These properties correspond directly to the properties you can specify in a service's WSDL contract. Some of the settings, such as the parameter style, can restrict how you implement a method. These settings can also effect which annotations can be used when annotating method parameters.
The @SOAPBinding
annotation is defined by the javax.jws.soap.SOAPBinding
interface. It provides
details about the SOAP binding used by the service when it is deployed. If the @SOAPBinding
annotation is not specified, a service is published
using a wrapped doc/literal SOAP binding.
You can put the @SOAPBinding
annotation on the SEI and any of the SEI's methods. When it is used on a method, setting of the method's
@SOAPBinding
annotation take precedence.
Table 1.2 shows the properties for the @SOAPBinding
annotation.
Table 1.2. @SOAPBinding
Properties
Property | Values | Description |
---|---|---|
style |
| Specifies the style of the SOAP message. If RPC style is specified, each message part within the SOAP body is a parameter or return value
and appears inside a wrapper element within the soap:body element. The message parts within the wrapper element correspond to
operation parameters and must appear in the same order as the parameters in the operation. If DOCUMENT style is specified, the contents of
the SOAP body must be a valid XML document, but its form is not as tightly constrained. |
use |
| Specifies how the data of the SOAP message is streamed. |
parameterStyle [b] |
| Specifies how the method parameters, which correspond to message parts in a WSDL contract, are placed into the SOAP message body. If BARE is
specified, each parameter is placed into the message body as a child element of the message root. If WRAPPED is specified, all of the input parameters
are wrapped into a single element on a request message and all of the output parameters are wrapped into a single element in the response message. |
[a] [b] If you set the style to |
Document bare style is the most direct mapping between Java code and the resulting XML representation of the service. When using this style, the schema types are generated directly from the input and output parameters defined in the operation's parameter list.
You specify you want to use bare document\literal style by using the @SOAPBinding
annotation with its style
property set to Style.DOCUMENT
, and its parameterStyle property set to ParameterStyle.BARE
.
To ensure that an operation does not violate the restrictions of using document style when using bare parameters, your operations must adhere to the following conditions:
The operation must have no more than one input or input/output parameter.
If the operation has a return type other than void, it must not have any output or input/output parameters.
If the operation has a return type of void, it must have no more than one output or input/output parameter.
![]() | Note |
---|---|
Any parameters that are placed in the SOAP header using the |
Document wrapped style allows a more RPC like mapping between the Java code and the resulting XML representation of the service. When using this style, the parameters in the method's parameter list are wrapped into a single element by the binding. The disadvantage of this is that it introduces an extra-layer of indirection between the Java implementation and how the messages are placed on the wire.
To specify that you want to use wrapped document\literal style use the @SOAPBinding
annotation with its
style property set to Style.DOCUMENT
, and its parameterStyle property set to
ParameterStyle.WRAPPED
.
You have some control over how the wrappers are generated by using the
@RequestWrapper
annotation and
the @ResponseWrapper
annotation.
Example 1.5 shows an SEI that uses document bare SOAP messages.
Example 1.5. Specifying a Document Bare SOAP Binding with the SOAP Binding Annotation
package org.eric.demo; import javax.jws.*; import javax.jws.soap.*; import javax.jws.soap.SOAPBinding.*; @WebService(name="quoteReporter") @SOAPBinding(parameterStyle=ParameterStyle.BARE) public interface quoteReporter { ... }