Coding a web service

There are two approaches to developing a web service, as follow:

  • The top-down approach, first develop the WSDL and use a utility, to generate the necessary glue code and stubs, then fill in the code for the business logic in the stub classes.
  • The bottom-up approach, you code the web service first and then you can package the web service and deploy it, the JBoss Web Services deployer will automatically generate the WSDL.

We use the last approach. Create the following Java file.


import java.util.HashMap;
import javax.jws.*;

public class CellPhoneTask {
 private HashMap<String, String> task;

 public CellPhoneTask() {

 public void init() {
 task = new HashMap<String, String>();
 task.put("Diana", "98123-123");
 task.put("Diego", "99456-452");
 task.put("Jesy", "99456-456");

 public String getCellPhone(String name) {
 String cellPhone = task.get(name);
 if (cellPhone == null)
 cellPhone = "00000-000";
 return cellPhone;


Finally, we need to create a web.xml file declaring the web service class as a servlet.

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
 xmlns="" xmlns:xsi=""

To deploy the web service; you copy the WAR file to the deploy directory. You can view web services deployed  to the application server by going to the URL http://localhost:8080/jbossws/services.

Click the URL identified by Endpoint Address to access the WSDL.




Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de

Estás comentando usando tu cuenta de Cerrar sesión /  Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión /  Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión /  Cambiar )


Conectando a %s

A %d blogueros les gusta esto: