Java Reference
In-Depth Information
Adding a Header with a Method Parameter
Problem
You want to indicate that your service operation accepts a SOAP header.
Solution
Use the @WebParam annotation properties header=true and mode=WebParam.Mode.IN . Here
is an example:
@WebMethod
public @WebResult(name="title") String
secureGetTitle(
@WebParam(name="id") String id,
@WebParam(name="usernameToken",
header=true, mode=WebParam.Mode.IN)
String usernameToken) {...}
Discussion
Using the header=true property of the @WebParam annotation as in the example just shown
will cause a WSDL to be generated that accounts for the header in the abstract WSDL. The
parameter will be pulled from the header of the message instead of from the body. The @We-
bParam.Mode.IN enum constant indicates that the parameter is only available on incoming
requests, and not on the response. That's true for the example here, but it is possible to map
header parameters to OUT modes.
Example 7-18 is a partial listing of what the resulting WSDL looks like when specifying a
header value as just shown.
Example7-18.Partial WSDL with headers specified
<message name="secureGetTitle">
<part name="parameters" element="tns:secureGetTitle"></part>
<part name="usernameToken" element="tns:usernameToken"></part>
</message>
<portType name="CatalogService">
<operation name="secureGetTitle"
parameterOrder="parameters usernameToken">
<input message="tns:secureGetTitle"></input>
<output message="tns:secureGetTitleResponse"></output>
Search WWH ::




Custom Search