In the top-down approach, the WSDL is created first, and the Java artifacts are generated using wsimport tool.
As a Java developer, I find the bottom-up approach simpler and quicker because:
- Java classes are faster to create than XML schema
- Creating a skeleton for a service endpoint interface (SEI) is faster than creating a WSDL skeleton.
In this approach, I very quickly create Java classes including the skeleton for the SEI, annotate them with basic JAX-WS annotations and generate a WSDL. Then, I customize the generated WSDL to be WS-I compliant (see also Which style of WSDL should I use?) and regenerate Java classes using wsimport.
An example using MavenLet's create a simple maven project with several model classes and a SEI implementation class:
Then, we generate the WSDL using jaxws-maven-plugin. Build section of the pom is shown below:
The generated WSDL file can be found under target/jaxws/wsgen/wsdl.
Then, we customize the namespaces and verify that the WSDL doesn't have Java specific parts. Then, we are ready to re-generate our Java classes.
Generated Java classes use XMLGregorianCalendar instead of java.util.Calendar for XML date and time types. This can be customized using a binding file. In addition, we can make our generated classes implement the Serializable interface. An example binding file is illustrated below:
Source code for these projects can be found in the quickstarts repository at GitHub.