代码片段(客户端调用)

package com.winning.util;

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;

public class WebServiceUtils
{
	public static int TIMEOUT = 100000;
	
	public static void main(String[] args) throws Exception
	{

		Object[] objects1=invokeWebService("http://192.168.1.125:8080/Axis2Test/services/userWebService?wsdl",
				"http://service.winning.com",
				"getUser",new Object[]{},new Class[]{User.class});
		System.out.println(((User)objects1[0]).getName());

		
		Object[] objects2=invokeWebService("http://192.168.1.125:8080/Axis2Test/services/userWebService?wsdl",
				"http://service.winning.com",
				"getUserNameById",new Object[]{1},new Class[]{String.class});
		System.out.println(objects2[0].toString());
		
		Object[] objects3=invokeWebService("http://localhost:8080/Axis2Test/services/productWebService?wsdl",
				"http://service.winning.com",
				"getProductNameByLsh",new Object[]{"123"},new Class[]{String.class});
		System.out.println(objects3[0].toString());
		
	}
	
	static public Object[] invokeWebService( String url, String nameSpace, String method, Object[] args, Class[] returnTypes )
			   throws AxisFault
	 {
	  RPCServiceClient serviceClient = new RPCServiceClient();
	  Options options = serviceClient.getOptions();
	  EndpointReference targetEPR = new EndpointReference( url );
	  options.setTo( targetEPR );
	  options.setTimeOutInMilliSeconds( TIMEOUT );
	  QName opName = new QName( nameSpace, method );
	  Object[] results = serviceClient.invokeBlocking( opName, args, returnTypes );
	  return results;
	 }
}


服务器端程序和客户端程序: http://down.51cto.com/data/1348838