Java Reference
In-Depth Information
Specifying an Operation Return Value
Problem
You want to define a return value for a Java method so that it maps to a WSDL output.
Solution
Use the
@WebResult
annotation to map to an existing
wsdl:output
or to customize how it's
generated.
Discussion
You can explicitly specify a Java method as a service operation by annotating it with the
@WebResult
annotation. But the annotation also allows you to specify certain properties of
how the operation will be represented in the WSDL. These are shown in
Table 7-3
.
Table7-3.@WebResult properties
Property
Purpose
name
The name of the return value. This will match the element name in the schema that is
mapped from the WSDL's message for the response. If the style is RPC and no
@WebRes-
ult.partName
has been specified, this value will be used as the
wsdl:part
that repres-
ents the return value. If the operation is document style or the return type maps to a head-
er, this will be the name of the schema element that represents the return value.
partName
The name of the
wsdl:part
that represents this return value. This is only used if the oper-
ation is RPC style or if the operation is document style and the parameter style is bare.
targetNamespace The XML target namespace for the element representing the return value if the style is
RPC or if the style is document and the parameter style is bare.
header
If set to true, the result will be pulled from a value set as a message header instead of one
set into the message body.
Here is an example of how specifying the name property affects the WSDL. Assume the
following Java method in a service implementation annnotated with an empty
@WebService
(which gives you the default style of document/literal):
@WebMethod
public @WebResult(name="doItOne") int
doIt(int x) {