You want to define an operation that requires SOAP headers and invoke it from a client.
In the service, use the
@WebParam annotation with your
operation parameter. Specify
header=true, and wrap your
parameter in a
T is the actual type of the parameter you want. On the
client, use a
Holder<T> to set the values of the
parameter elements and get the return values with a reference.
The following examples illustrate how to use a
to handle the SOAP headers required for using a web service. This is a
command-line client for the web service, and it is totally portable; it
doesn’t rely on proprietary extensions within Glassfish or another
container. The web service and WSDL are shown as well to help aid your
understanding the process.
First, you’ll create a web service using the “Start from Java” approach. This is easy to do, and
lets you generate a WSDL with
wsgen that indicates the
required header values. Most containers will automatically generate a
WSDL for you on deployment, so all you should need to do is create the
Java class as part of a WAR project within your favorite IDE, and
package the class in WEB-INF/classes as you would
any other regular Java class. The web service is shown in Example 7-19.
Example 7-19. Email verifier web service requiring credentials in SOAP headers
package com.soacookbook; import javax.jws.WebParam; import javax.jws.WebService; import javax.xml.ws.Holder; /* * Very simple ...