Developing the Web Services’ client

The client is a command-line application that takes a list of names on the command line and prints the phone numbers.
First, you generate the stubs for the client from WSDL as follows:

wsconsume -k http://127.0.0.1:8080/CellPhoneWebService/task?wsdl

If you develop the service and the client on the same machine, make sure that the client doesn’t have visibility to the files that make up the web service; otherwise, the compiler will get confused. For example, the generated files contain an interface named org.app.ws.CellPhoneTask, which is the same name as the class that implements the web service if you used a bottom-up approach. If both are available to the compiler or the runtime, the wrong one might be used.
The client code is show below:

package org.app.ws;

import static java.lang.System.out;

public class Client {
	public static void main(String[] args) {
		if (args.length > 0) {
			CellPhoneTaskService svc = new CellPhoneTaskService();
			CellPhoneTask task = svc.getCellPhoneTaskPort();
			for (int i = 0; i < args.length; i++) {
				String cellPhone = task.getCellPhone(args[i]);
				out.println("Cell phone number task for " + args[i] + " is " + cellPhone);
			}
		}
	}
}

The contents of the client JAR files is the following:

+---CellPhoneClient
¦   ¦
¦   +---bin
¦   ¦   +---org
¦   ¦       +---app
¦   ¦           +---ws
¦   ¦                   CellPhoneTask.class
¦   ¦                   CellPhoneTaskService.class
¦   ¦                   Client.class
¦   ¦                   GetCellPhone.class
¦   ¦                   GetCellPhoneResponse.class
¦   ¦
¦   +---src
¦       +---org
¦           +---app
¦               +---ws
¦                       CellPhoneTask.java
¦                       CellPhoneTaskService.java
¦                       Client.java
¦                       GetCellPhone.java
¦                       GetCellPhoneResponse.java

Etiquetas:

Responder

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

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. 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 )

Google+ photo

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

Conectando a %s


A %d blogueros les gusta esto: