Monday, 18 April 2011

Building Web Services with JAX-WS

JAX-WS is Java API for XML Web Services. It is a technology for building web services and clients that communicate using XML. JAX-WS allows developers to write message-oriented(basic unit of communication is message and not the underlying operation) as well as RPC-oriented (distributed function call interface which is tightly-coupled) web services.


Any operation is invoked by an XML-based protocol such as SOAP. The SOAP specification defines the envelope structure encoding rules and conventions for representing web service invocations and responses. These calls and responses are transmitted as SOAP messages (XML files) over HTTP.


SOAP messages appear complex but the good thing is that JAX-WS API hides this complexity from the application developer. 
In JAX-WS, on the server side you write the web service operations by defining methods in interface(s) written in the Java programming language. You need to implement one or more of the interfaces. 
It is equally easy to write client code. A client creates a proxy (a local object representing the service) and then simply invokes methods on the proxy. With JAX-WS you do not generate or parse SOAP messages. Thanks to JAX-WS runtime system that converts the API calls and responses to and from SOAP messages!


With JAX-WS web services and clients you've big advantage: the platform independence of the Java programming language. In addition JAX-WS is not restrictive: a JAX-WS client can access a web service that is not running on the Java platform and vice versa. This flexibility is possible because JAX-WS uses technologies defined by the World Wide Web Consortium (W3C): HTTP SOAP and the Web Service Description Language (WSDL, called 'wisdel'). WSDL specifies an XML format for describing a service as a set of endpoints operating on messages.


The three most popular implementations of JAX-WS are Metro, Axis and CXF.
Metro: It is developed and open sourced by Sun Microsystems. It incorporates the reference implementations of the JAXB 2.x data-binding and JAX-WS 2.x web services standards along with other XML-related Java standards.


Axis: The original Apache Axis was based on the first Java standard for Web services which was JAX-RPC. This did not turn out to be a great approach because JAX-RPC constrained the internal design of the Axis code and caused performance issues and lack of flexibility. JAX-RPC also made some assumptions about the direction of Web services development...which turned out to be wrong!
By the time the Axis2 development started, replacement for JAX-RPC had already come into picture. So Axis2 was designed to be flexible enough to support the replacement web services standard on top of the base framework. Recent versions of Axis2 have implemented support for both the JAXB 2.x Java XML data-binding standard and the JAX-WS 2.x Java web services standard that replaced JAX-RPC(JAX-RPC: Java API for XML-based Remote Procedure Calls. Since RPC mechanism enables clients too to execute procedures on other systems it is often used in a distributed client-server model. RPC in JAX-RPC is represented by an XML-based protocol such as SOAP).


CXF: Another web services stack by the Apache. Though both Axis2 and CXF originated at Apache, they take very different approaches about how web services are configured and delivered. CXF has is very well documented and has much more flexibility and additional functionality if you're willing to go beyond the JAX-WS specification. It also supports Spring. 


CXF is my choice, what is yours?

No comments:

Post a Comment