How to: Create Web service from basic Java Class

Contents

Overview

Demonstrates a basic stateless "Hello" Web Service. The Java object that implements the service persists for the duration of the application lifetime.

Quick Start

Ensure that you have installed the required software and set up your environment. You must have OC4J running. If it is not running on localhost, port 8888, you'll have to modify the ANT script (build.xml) to use the correct host and port to your server.

Once you have the server configured and running, just type ant from the basic/stateless directory. The service artifacts and implementation class will be compiled and placed into a WAR which is then placed into an EAR. The EAR will be deployed to OC4J. Next the stubs and client will be compiled. Finally the service will be invoked by the client and you should see the output both in the server's message output and on the stdout of the client.

Step By Step

Ant tasks have been configured for easy running of this demo.

  1. Generate the service artifacts:

    To create a deployable application, type.

     % ant gen-service 
    
    This should result in a j2ee webservices compliant application file: dist/hello.ear.

  2. Deploy the Service and Bind the Application

    To deploy and bind the application.

    % ant deploy-demo 
    

    Visit the http test page by going to http://localhost:8888/hello/HelloService to make sure that the application has been deployed properly.

  3. Run the client

    In this step you will generate the stubs for the service. A client application uses a stub to invoke operations on a remote service. Examine the file client-config.xml. This is the configuration file that the WebServices Assembler (WSA) tool uses to generate the stubs. To generate the stubs type: ant gen-stubs. The source for the stubs will be placed in build/src/client.

  4. Run the demo

    To run the client, issue:

     % ant run-demo 
    
    You should see a result like :
    
         "Hello Duke!"
    
Compatibility Note

The behavior of a standard Java class Web Service in the 9i Web Services stack is different: by default, a new Java service instance is created on every call. If you have written a Java service class that exploits this behavior in 9i, you will have to rewrite it for Oracle JAX-RPC Web Services.