Java Reference
In-Depth Information
Using the @WebParam annotation
The
@javax.jws.WebParam
annotation is used to customize a parameter for the web
service part message generated in the WSDL document. This annotation is placed on the
arguments to a method being exposed as a web service. The full definition for this annota-
tion is as follows:
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER})
public @interface WebParam {
String name() default "";
String partName() default "";
String targetNamespace() default "";
Mode mode() default Mode.IN;
boolean header() default false;
static final enum Mode {
public static final IN, public static final OUT, public static final
INOUT;
}
}
The following code snippet demonstrates how this annotation is used. As you'll see, para-
meters can be used to pass data into a web service, return a result from a web service, or
both:
@WebMethod
public Long addBid(
@WebParam(name="user", mode= WebParam.Mode.IN) String userId) {
...
}
The
name
property specifies the
name
parameter for the message in the WSDL. If a name
isn't specified, the default value generated will be the same as the name of the argument.
The
targetNamespace
property is used to customize the XML namespace for the mes-
sage part. If a
targetNamespace
isn't specified, the server will use the namespace of
the web service.
The
mode
property specifies the type of the property with valid options being
IN
,
OUT
, and
INOUT
(both). This property determines the direction of the parameter: whether a value is
being passed in or is being passed back, or if the value is being passed in and also returned.
You can think of
INOUT
like pointers in C++ where an argument to a method can be a