Friday, November 11, 2005

make a web service client using axis

java org.apache.axis.wsdl.WSDL2Java SimilarSearch.wsdl

will generate a set of helper classes according to the wsdl definition.

then make a client java as below:

/*
* Created on 08-Nov-05
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/

/**
* @author ft
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/

package SimilarSearch;

import java.rmi.RemoteException;

import javax.xml.rpc.ServiceException;

public class similarSearchClientTester {

public static void main(String[] args) {

// create an instance of our service locator
SimilarSearchServiceLocator locator = new SimilarSearchServiceLocator();

// create an instance or our SoapBindingStub
SimilarSearchBindingStub stub=null;
try {
stub = (SimilarSearchBindingStub) locator.getSimilarSearchPort();
} catch (ServiceException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}

SimilarSearchIn in = new SimilarSearchIn();
in.setNumber("ct01003");

// make a call to a method we created in our web service
try {
System.out.println("read to similar search");
SimilarSearchOut out = stub.doSearch(in);
System.out.println("result:"+out.toString());

} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
}

No comments: