Exercise 5: Web Services

by Roman Schmidt


The goal of this exercise is to understand basic Web Services concepts. The exercise uses the database created in exercise 2 (JSP/JDBC) to retrieve the current balance of a customer given by her/his name. You have to sum all balances of all accounts of this customer and return the overall balance.

In the following a "Hello World" example is given to make you familiar with the used environment and tools followed by a detailed description of the exercise.

"Hello World" example

The archive contains all required files to demonstrate the "Hello World" example. Extract the files in a new directory created in your home directory, e.g., ~/HelloWorld/. First of all you should get familiar with Ant files such as build.xml. It contains a set of targets which can execute any application, e.g., java, javac, wscompile, rm, mkdir, ... The application server uses an extended version called asant to support developers.

How to run the example:

  1. edit the build.xml file and set the value of the user property to your user number
  2. compile the example by typing asant in a console (this executes the default target of the default ant file - build.xml)
  3. open the deploytool and create a new Web Component
  4. choose a name for your WAR file, e.g.,~/HelloWorld/build/helloService.war
  5. set a Context Root: /helloService
  6. add all files of the build directory to the Content
  7. choose the Web Services Endpoint type at the next page
  8. select the available WSDL and Mapping file
  9. select the Service Endpoint Implementation: cis.HelloImpl
  10. select the Service Endpoint Interface: cis.HelloIF
  11. the Namespace is http://lsirwww.epfl.ch/ and the Local Part is HelloIFPort for the WSDL Port
  12. after finishing the wizard select the helloImpl in the tree
  13. add an alias /hello in the Aliases tab
  14. in the Endpoint tab, select hello for the Endpoint Address in the Sun-specific Settings frame
  15. deploy the component
  16. run the client (in a console): asant run

You should have seen Hello Duke! as output of the client. If not you can test your service by using your browser to retrieve the WSDL file at: http://localhost:800Y/helloService/hello?WSDL. The service is deployed if you can see a WSDL file describing your service.

You can change the delivered greeting by changing the run target of your build.xml file.

Please make yourself familiar with all files of this example and may read Chapter 8 of the J2EE tutorial if you are interested in further details.

Exercise description

You can use the "Hello World" example as starting point for the exercise. I propose to change the example only step by step and always try if you can still deploy and invoke the service. Otherwise you may not be able to fix an error because some error messages of the application server are not very meaningful and helpful.

The interface for your Web service is given below:

package cis;

import java.rmi.Remote;
import java.rmi.RemoteException;

public interface BankIF extends Remote {
  public Float getBalance(String name) throws RemoteException;
}