Java Reference
In-Depth Information
The @RequestWrapper and @ResponseWrapper annotations capture information that JAXB
needs to perform the marshaling and unmarshaling operations. If your service is defined as us-
ing document/literal mode, as ours is, this annotation also serves to resolve overloading con-
flicts.
Now, let's write a quick program to invoke the generated client code and get a result from
your service. Here are the steps in their simplest form, stripped of any unnecessary items so
you can get the clearest picture.
First, write the invoker called CalculatorInvoker.java ( Example 6-3 ) . Navigate to the top-
level directory that you passed to the wsimport tool earlier. For me this was “/home/ehewitt/
soacookbook/code/imported”. You'll write your client there.
Example6-3.CalculatorInvoker.java will invoke the generated service endpoint code
import org.me.calculator.*;
public class CalculatorInvoker {
public static void main(String... arg) {
CalculatorWSService service = new CalculatorWSService();
CalculatorWS port = service.getCalculatorWSPort();
int result = port.add(2, 3);
System.out.println("Result: " + result);
}
}
The class in Example 6-3 simply creates a service instance, uses it to get the port, and uses the
port to call the business method, add . Let's compile it, making sure the generated classes in
the current directory are on your classpath:
>javac -cp . CalculatorInvoker.java
Then you can run it:
>java -cp . CalculatorInvoker
Result: 5
That's all there is to a basic client. Web services have come a long way with JAX-WS.
For more information on using wsimport specifically, you can invoke it with no arguments to
print the help.
Finally, there are a few considerations to keep in mind with using generated clients:
Search WWH ::




Custom Search