Transform Existing Java Classes into a Web Service/Client
A good demonstration of the development process is to customize the example from the previous section using your own Java class file. Add the "@WebService" annotation to the line after the imports and make the following changes to the additional files in order:
- Copy the JAXWS_EXAMPLE directory and change the two directories named "simpleExample" in "simpleExample/src/simpleExample" to your project name.
- Replace SimpleJAXWS.java and SimpleException.java with your new @WebService java file and any accompanying exceptions.
- Rename SimpleMethodClient.java to your class name.
- Open all the .java, .properties, and .xml files (including build.xml) in an editor, and use batch search/replace to make the following changes (be sure the replacements are case sensitive):
- Replace all "simpleexample" references with your project name.
- Replace all "simpleMethod" references with your method name.
- Replace all "SimpleJAXWS" references with your class name.
- Replace all "simplemethod" references with your URL pattern.
- Replace all "SimpleException" references with your exception class name.
- Replace all remaining "SimpleMethod" references with your method name (these occur in pointers to the derivative classes).
- Now you must edit the client class in accordance with the parameters and return the type of the Web service.
- Lastly, run the ant targets server and client, and run the same as above.
By following these steps you have transformed your own Java class into a Web service, enabling it to communicate over a network in a distributed computing environment.
Raw SOAP for Web Services Is Now Obsolete
With the advent of JAX-WS, the use of raw SOAP for Web services has become deprecated. This means that popular projects such as Apache Axis (Apache's implementation of SOAP) are no longer necessary for Web service developers. By abstracting the protocol binding, JAX-WS can provide simultaneous support for SOAP 1.1 and 1.2. By utilizing annotations, simplified build tools, and JAXB, JAX-WS removes many of the unnecessary complications of JAX-RPC.