Tutorials

Jini Example
Jxta Example
Web Services

Related

Jxta
Jini
Web Services

For More Info

From P2P to Web Services and Grids: Peers in a Client/Server World
Ian J. Taylor, 2004
Publisher: Springer
ISBN: 1-85233-869-5
Once the Web service is deployed, it can be invoked by using the Axis toolkit from a Java program. For our example, the following code provides the client-side implementation:
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;

public class Client {
    public static void main(String [] args) {
        try {
            String endpointURL =
              "http://localhost:8080/axis/services/SilverService";

            Integer in = new Integer(10);
            Service service = new Service();
            Call call = (Call) service.createCall();

            call.setTargetEndpointAddress(
                    new java.net.URL(endpointURL) );
            call.setOperationName(
                    new QName("SilverService", "getIncrement") );

            Object ret = call.invoke( new Object[] { in } );

            System.out.println("Object = " + ret.getClass().getName());
            System.out.println("Number Returned : " + ret.toString());
        } catch (Exception e) {
            System.err.println(e.toString());
        }
    }
}

It can be downloaded here: Client.java

Here, first, we create new Axis Service and Call objects, which store metadata about the service to invoke. We set the endpoint address URL to specify the actual location of the class. Here, our SilverService class is located in the http://localhost:8080/axis/services/ directory. We then set the operation name, i.e., the method call that we wish to invoke on the service (i.e., getIncrement()). We can now invoke the service by passing it any Java Object or an array of Java Objects. Here, we pass it a Java Integer containing the value 10. To compile the client-side implementation (assuming you have set your CLASSPATH correctly) is as follows:

javac Client

To invoke the service you run this, just as any other the Java application, as follows:

java Client

which will produce the following output:

Object = java.lang.Integer
Number Returned : 11

undeploy this Web service - back to index