Java Reference
In-Depth Information
Creating a Web Service That Uses Complex Types
Based on Custom WSDL and a Custom Schema
Problem
You have to program in the real world, not Hello World, so you want to write a web service
that sends and receives complex types based on a schema that you have written. That schema
is referred to by a WSDL that you have written, and you want to be sure to maintain the con-
straints specified in your schema. You are not using a Provider, but a class annotated with
@WebService , so you need to generate portable types from the schema before your web ser-
vice will compile.
Solution
Basically, you will use the @WebService.wsdlLocation annotation and generate your
classes at the right point in your build with the XJC Ant task.
Discussion
You will create a Credit web service that defines a single operation: authorize . It will accept
a CreditCard complex type and execute some business logic to determine what amount the
card should be authorized for. It will then return a custom Authorization Java type.
You'll write each artifact in the order you would in the real world: the schema, the WSDL, the
Java web service, and the build script that puts it all together and deploys it.
Schema
The schema in Example 7-1 contains elements that specify parts of a credit card and an au-
thorization amount. The idea in this solution is to create a complex schema, such as you might
use in the real world, that is still not overly long.
This schema is suitable for use with a parameter style of bare because the two elements
defined ( creditCard and authorization ) represent the actual documents we want to ex-
change in the invocation. If you want to use a wrapped parameter style, specify elements that
act as the wrappers for your real elements.
Example7-1.Credit.xsd credit card schema
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
Search WWH ::




Custom Search