The major differences between the two standards are:
- JAX-WS supports SOAP 1.2, and XML over HTTP.
- JAX-RPC supports WS-I’s Basic Profile (BP) version 1.0. JAX-WS supports BP 1.1. (WS-I is the Web services interoperability organization.)
- JAX-RPC maps to Java 1.4. JAX-WS maps to Java 5.0. JAX-WS relies on many of the features new in Java 5.0.
- JAX-WS’s data mapping model is JAXB, unlike JAX-RPC. which creates LiteralSerializer classes for all the data elements.
- JAX-RPC handlers rely on SAAJ 1.2. JAX-WS handlers rely on the new SAAJ 1.3 specification.
- JAX-WS heavily relies on annotations.
Now, for the implementation. I created a sample web service application based on JAX-WS (the pack comes with the Java WSDP). To develop a web service, two tasks are provided: wsimport and wsgen.
wsimport creates service artifacts and client stubs by looking into the WSDL. wsgen reads a web service endpoint class and generates all the required artifacts for web service deployment, and invocation. Both need to be used together to create a web service. The steps that need to be followed for creating a web service and deploying it can be listed down as follows (refer to the build.xml in the uploaded zip file):
- Create the WSDL (assuming top-down approach) .
- Generate the service interfaces using wsimport. Additionally, server binding configuration xml can be used to specify the namespace mapping with Java packages, and specifying the server side handlers. Refer to the ant task – create-server-wsdl.
- Implement service endpoint using the interface.
- Generate the service artifacts from the implemented class using wsgen. This generally comprises of JAXB objects.
- Create a war file, which has the following structure:
(For steps 4 and 5, refer to the ant task – build-war)
The sun-jaxws.xml is an additional file which needs to be created. It specifies the end point interfaces, the implementation class, the port, and the url pattern for the service, which is used by the container in which the service is deployed.
Once the war is created, it can be deployed on any web server/ application server. I tested it on both Tomcat web server 5 and Sun Application Server 9.
The client stubs can be generated using the wsimport and specifying the WSDL file. (ant task – create-client-wsdl). Again, the binding configuration file for the client can be used to provide namespace mapping and client side handlers. As with JAX-RPC implementation, the wsimport and wsgen tasks are dependent on a number of configuration xml files. But unlike the wsdeploy task in JAX-RPC, where a valid web.xml deployment descriptor is created with a listener class and a JAX-RPC servlet automatically, here, in JAX-WS, these entries have to be manually entered. Also, there is a heavy use of annotations, and JAXB objects.