Chapter 20. Implementing JAX-RPC Web Services

Table of Contents

20.1. Overview
20.2. Implementing a Web Service from a Java Class
20.2.1. Example
20.2.2. Implementation Principles of Java Web Services
20.3. Implementing a Web Service from an EJB
20.3.1. Example
20.3.2. Implementation Principles of EJB Web Services
20.4. Implementing Web Services from WSDL
20.5. Using SAAJ

This chapter describes various ways to implement JAX-RPC web services.

Implementing a JEUS JAX-RPC web service requires the writing and compiling of Java code, which is a web service back-end component. JEUS JAX-RPC supports two types of web service back-end components, Java class and EJB.

The following procedures describe the main steps for implementing a JEUS JAX-RPC web service.

  1. Write the Java code for the back-end components that make up the web service.

  2. To process a SOAP request or response information or directly access the SOAP attachments, create SOAP message handlers and handler chains.

  3. Compile the Java code.

Creating a web service from a Java class is the simplest way of implementing a JAX-RPC web service. Let's start out with a simple example.

When developing a JavaEE web service, EJB may be more complex than the Java web service programming model, but it provides more functions. The complexity is due to the automatic transaction management.

A solid understanding of EJBs is required to implement an EJB web service. This section may be skipped if EJB will not be used for implementing web services.

A stateless session EJB can also be exported as a web service, and it also requires an SEI.

The following SEI (HelloIF.java) defines a web service operation called sayHello(String).


An SEI defines the web service operations to be exposed for external access through the SOAP protocol. An SEI should directly or indirectly extend the java.rmi.Remote interface, and each method must throw the java.rmi.RemoteException exception. After the web service operations are defined, the actual logic must be implemented in the implementation class. In the following example, an EJB is used as the implementation class.

The following is an example of a remote interface class.


The following is the home interface class.


The following is the EJB endpoint bean class that contains the implementation of the session bean.


Most of this guide assumes that a user is implementing a web service by writing the backend component first. However, an existing WSDL can also be used to create the implementation code. In this case, the wsdl2java Ant task can be used to generate a web service template. The Ant task uses an existing WSDL file, or one created by the user.

The following example shows a sample build file used to execute the wsdl2java Ant task.


The following command can be used to generate a web service source code template.

prompt>ant do-package-war

The service interface implementation can be created by referring to '"20.2. Implementing a Web Service from a Java Class"' and '"20.3. Implementing a Web Service from an EJB"'.

Note

For further information about the wsdl2java task, refer to JEUS Reference Book. "4.10. wsdl2java" and JEUS Reference Book. "5.5.2. wsdl2java".

A SOAP message is usually included in the SOAP body. However, it is sent as a SOAP attachment when a specific Java type is used as the parameter or return value of a method that implements the web service operation.

JEUS web services define the Java data types and their corresponding MIME types in a SAAJ(SOAP with Attachments API for Java) as in the following.


For each MIME type, JAX-RPC endpoint stub marshals and unmarshals the corresponding Java type to and from an encoded data stream. For more information, refer to
"Chapter 23. Creating SOAP Message Handler of JAX-RPC Web Service".