JAX-RPC

The Java API for XML-based RPC (JAX-RPC) specification enables you to develop SOAP-based interoperable and portable Web services and Web service clients. JAX-RPC 1.1 provides core APIs for developing and deploying Web services on a Java platform and is a required part of the J2EE 1.4 platform. The J2EE 1.4 platform allows you to develop portable Web services. Web services can also be developed and deployed on J2EE 1.3 containers.

WebSphere Application Server implements JAX-RPC 1.1 standards.

The JAX-RPC standard covers the programming model and bindings for using Web Services Description Language (WSDL) for Web services in the Java language. JAX-RPC simplifies development of Web services by shielding you from the underlying complexity of SOAP communication.

On the surface, JAX-RPC looks like another instantiation of remote method invocation (RMI). Essentially, JAX-RPC allows clients to access a Web service as if the Web service was a local object mapped into the client's address space even though the Web service provider is located in another part of the world. The JAX-RPC is done by using the XML-based protocol SOAP, which typically rides on top of HTTP.

JAX-RPC defines the mappings between the WSDL port types and the Java interfaces, as well as between Java language and XML schema types.

A JAX-RPC Web service can be created from a JavaBean or a enterprise bean implementation. We can specify the remote procedures by defining remote methods in a Java interface. You only need to code one or more classes that implement the methods. The remaining classes and other artifacts are generated by the Web service vendor's tools. The following is an example of a Web service interface

package com.ibm.mybank.ejb;
import java.rmi.RemoteException;
import com.ibm.mybank.exception.InsufficientFundsException;
/**
  * Remote interface for Enterprise Bean: Transfer
  */
public interface Transfer_SEI extends java.rmi.Remote {
      public void transferFunds(int fromAcctId, int toAcctId, float amount)
            throws java.rmi.RemoteException;

}

The interface definition in JAX-RPC must follow specific rules; most of these rules are from RMI with some additions for JAX-RPC. The following are the rules for defining a JAX-RPC interface:

  • The interface must extend java.rmi.Remote just like RMI.

  • Methods must throw java.rmi.RemoteException.

  • Method parameters cannot be remote references.

  • Method parameter must be one of the parameters supported by the JAX-RPC specification. The following list are examples of method parameters that are supported. For a complete list of method parameters see the JAX-RPC specification.

  • Methods can take value objects which consist of a composite of the types previously listed, in addition to aggregate value objects.

A client creates a stub and invokes methods on it. The stub acts like a proxy for the Web service. From the client code perspective, it seems like a local method invocation. However, each method invocation gets marshaled to the remote server. Marshaling includes encoding the method invocation in XML as prescribed by the SOAP protocol.

The following are key classes and interfaces needed to write Web services and Web service clients:

  • Service interface: A factory for stubs or dynamic invocation and proxy objects used to invoke methods

  • ServiceFactory class: A factory for Services.

  • loadService

    The loadService method is provided in WAS v6 to generate the service locator which is required by a JAX-RPC implementation. If you recall, in previous versions there was no specific way to acquire a generated service locator. For managed clients you used a JNDI method to get the service locator and for non-managed clients, you were required to instantiate IBM's specific service locator ServiceLocator service=new ServiceLocator(...); which does not offer portability. The loadService parameters include:

    • wsdlDocumentLocation: A URL for the WSDL document location for the service or null.

    • serviceName: A qualified name for the service

    • properties: A set of implementation-specific properties to help locate the generated service implementation class.

  • isUserInRole

    The isUserInRole method returns a boolean indicating whether the authenticated user for the current method invocation on the endpoint instance is included in the specified logical role.

    • role: The role parameter is a String specifying the name of the role.

  • Service

  • Call interface: Used for dynamic invocation

  • Stub interface: Base interface for stubs

If you are using a stub to access the Web service provider, most of the JAX-RPC API details are hidden from you. The client creates a ServiceFactory (java.xml.rpc.ServiceFactory). The client instantiates a Service (java.xml.rpc.Service) from the ServiceFactory. The service is a factory object that creates the port. The port is the remote service endpoint interface to the Web service. In the case of DII, the Service object is used to create Call objects, which one can configure to call methods on the Web service's port.

To learn more about JAX-RPC see Web services: Resources for learning.


 

See Also


Web Services for J2EE specification

 

See Also


Web services: Resources for learning