HOME | J2ME | Struts | AJAX | SOAP | SOA MEDIA STREAMING AXIS |
AXIS STEP BY STEP
Web Services
Axis Introduction
Installations
Hello World
Using Eclipse
POJO Service
POJO Client
AXIOM Service
AXIOM Client

 

 

POJO based Axis Client

Back | Tutorial Home | Next

Axis provides simple API’s to access the Axis services. We will learn to create an Axis client in this section

To access the address book service we will need following information

  • End point reference or URL - http://localhost:8080/axis2/services/AddressBookService
  • Target name space URI- http://service.demo, This name space can be found at WSDL URL of the service(http://localhost:8080/axis2/services/AddressBookService?wsdl)
  • The operations we can perform on this service are setAddressBook and getAddressBook (these published operations can also be found in WSDL file)

Now that we have got the all the necessary data needed by the client lets look at the client code. The explanation of client code is given in code comments.

package demo.client;

import javax.xml.namespace.QName;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;
import demo.data.AddressBook;


public class AddressBookClient {

  public static void main(String[] args1) throws AxisFault {
	
   // Create client to access a service
   RPCServiceClient serviceClient = new RPCServiceClient();
		
   // Get client options to interact with the service 
   Options options = serviceClient.getOptions();
		
   // Create service end point reference
   EndpointReference endPointRef = 
   new EndpointReference("http://localhost:8080/axis2/services/AddressBookService");
		
   // Set end point reference to service client options
   options.setTo(endPointRef);
		
   // Setting address book values
   // Create qualified name space
   QName qualsetAddressBook = new QName("http://service.demo", "setAddressBook");
		
   AddressBook addressData = new AddressBook();
		
   addressData.setFirstName("Tom");
   addressData.setLastName("Lee");
   addressData.setPhoneNumber(635364578);
   addressData.setAddress("36 Drury Lane, London");
		
   Object[] objSetaddressBookVal = new Object[] {addressData};
		
   serviceClient.invokeRobust(qualsetAddressBook, objSetaddressBookVal);
		
   // Fetch address book values 
   QName qualgetAddressBook = new QName("http://service.demo", "getAddressBook");
		
   Object[] objGetaddressBookVal = new Object[] { };
   Class[] returnTypes = new Class[] { AddressBook.class };
		
   // Send service request
   Object[] response = serviceClient.invokeBlocking(qualgetAddressBook,
   objGetaddressBookVal, returnTypes);
		
   AddressBook result = (AddressBook) response[0];
		
   // Display Results
   System.out.println("First Name: " + result.getFirstName());
   System.out.println("Last Name: " + result.getLastName());
   System.out.println("Phone No: " + result.getPhoneNumber());
   System.out.println("Address: " + result.getAddress());
  }
}

Now finally execute target “rpc.client” in the ant build file through eclipse to compile, jar and run the axis client

You should get following results in the Eclipse console

First Name: Tom
Last Name: Lee
Phone No: 635364578
Address: 36 Drury Lane, London

Back | Tutorial Home | Next

site comments powered by Disqus
Download our free toolbar

toolbar powered by Conduit

| Copyright © 2009. All rights reserved | Terms and Conditions | About | Contact | Feed Back |