Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Even though JAX-RPC is still supported by Sunin Java EE 5, it lacks many advanced features that JAX-WS has like Annotations, JAXB Binding, SOAP 1.2, RESTful Services etc. So It , it is strongly recommended that you use JAX-WS instead of JAX-RPC for implementing Web Services in Java.

...

The most notable change in JAX-WS 2.0 is the use of JAXB 2.0 for data-binding between Java and XML. JAX-RPC 1.0 specified a limited mapping between XML and Java.
This effectively eliminates the need of using jaxrpcmapping.xml JAX-RPC mapping file where we define the mapping between Java and WSDL. But also imposes a condition that the return and request values can be able to bind to JAXB. Again, considering the wide variety of data types supported by JAXB it shouldn't be a problem.

...

JAX-WS 2.0 relies heavily on the use of Annotations. These annotations are used to customize the mapping from JAVA to XML schema/WSDL and are used at runtime to create the necessary files.
Geronimo uses the Sun provided JAXWSTools wsgen utility to create the WSDL file and another stubs on the fly at the deploy time by processing the annotations specified.

...

JAX-RPC and JAX-WS both support SOAP 1.1. The default binding supported by JAX-WS is SOAP 1.1 over HTTP. But it can also support SOAP 1.2 binding over HTTP. As a java Java programmer you might not encounter any difference between SOAP 1.1 and SOAP 1.2

...

Code Block
titleJAX-RPC Converter SEI
borderStylesolid


package org.apache.geronimo.samples.jaxrpc;

import java.math.BigDecimal;
import java.rmi.Remote;
import java.rmi.RemoteException;


public interface Converter extends Remote {
	
	public BigDecimal dollarToRupees(BigDecimal dollars) throws RemoteException;
	public BigDecimal rupeesToEuro(BigDecimal rupees) throws RemoteException;

}

Code Block
titleJAX-WS Converter SEI
borderStylesolid

package org.apache.geronimo.samples.jaxrpc;

import java.math.BigDecimal;
import javax.jws.WebService

@WebService(name = "Converter", targetNamespace = "http://org.apache.geronimo.samples.jaxws")
public interface Converter {
	
	public BigDecimal dollarToRupees(BigDecimal dollars);
	public BigDecimal rupeesToEuro(BigDecimal rupees);

}

The main differences that you can find here are:

  • Annotations - JAX-WS requires that all SEIs include the @WebService annotation
  • java.rmi.Remote - The JAX-RPC SEI extends the java.rmi.Remote interface. JAX-WS no longer requires this.

Also, a JAX-WS SEI mmakes makes extensive use of annotations to specify the JAVA Java to WSDL mapping whereas this information does not exist in any form of JAX-RPC SEI (which requires jaxrpcmapping.xml JAX-RPC mapping file to map JAVA Java to WSDL)

Deployment Descriptor

The deployment descriptor (web.xml) hasn't changed from JAX-RPC to JAX-WS where we just need to expose a POJO class as a servlet and JAXWSTools the server creates the artifacts on the fly whereas for JAX-RPC we need to specify the WSDL and JAX-RPC mapping file locations.
With JAX-WS mapping to JavaEE5 Java EE 5 and taking the advantage of annotations, the need for Web Service descriptor document webservices.xml is eliminated as a Web Service can be effectively described using the annotations

...

Code Block
titleJAX-RPC Converter Client
borderStylesolid

package org.apache.geronimo.samples.jaxrpc;

import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.rpc.Service;
import javax.xml.rpc.ServiceFactory;
import javax.xml.rpc.ServiceException;

//a part of client
URL url = new URL("http://localhost:8080/jaxrpc-converter/converter?wsdl");
QName qname = new QName("http://org.apache.geronimo.samples.jaxrpc/","ConverterService");
ServiceFactory factory = null;
Service service = null;
try {
	factory = ServiceFactory.newInstance();
	Service service = factory.createService(url, qname);
} catch (ServiceException e) {
	e.printStackTrace();
}
Converter conv = (Converter) service.getPort(Converter.class);

Code Block
titleJAX-WS Converter Client
borderStylesolid

package org.apache.geronimo.samples.jaxrpc;

import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;

//a part of client
URL url = new URL("http://localhost:8080/jaxrpc-converter/converter?wsdl");
QName qname = new QName("http://org.apache.geronimo.samples.jaxrpc/","ConverterService");
Service service = Service.create(url, qname);
Converter conv = (Converter) service.getPort(Converter.class);

...

JAX-WS introduced RESTful Web Services as successor for SOAP based Web Service. RESTful services already got quite support from many vendors like Google AdSense, Yahoo API's, Amazon etc.
The important things that are introduced in JAX-WS to support RESTful services are:

...

The Dispatch API is intended for advanced XML developers who prefer to use XML constructs at the java.lang.transform.Source or javax.xml.soap.SOAPMessage level. For added convenience use of the Dispatch API with JAXB data-bound objects is supported.

Asynchronous Operations

A major difference in operation mapping for JAX-WS over JAX-RPC is the introduction of asynchronous operations. Any WSDL operation with a two-way message flow, or one where the client expects to receive a response, can be mapped to an asynchronous Java representation.
For further reference about asynchronous operations in JAX-WS refer to the references section.

...