package axis2;
import javax.xml.namespace.QName;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;
public class Client {
public static void main(String[] args) throws Exception {
// ObjectFactory factory = new ObjectFactory();
// SimpleMethod method=factory.createSimpleMethod();
// System.out.println("client");
RPCServiceClient serviceClient;
serviceClient = new RPCServiceClient();
Options options = serviceClient.getOptions();
// 这一步指定了该服务的提供地址
EndpointReference targetEPR = new EndpointReference("http://localhost:8888/axis2/services/simpleServer?wsdl");
// 将option绑定到该服务地址
options.setTo(targetEPR);
// 添加具体要调用的方法,这个可以从该服务的wsdl文件中得知
// 第一个参数是该服务的targetNamespace,第二个为你所要调用
// 的operation名称
QName namespace = new QName("http://axis2", "simpleMethod");//axis2为服务端项目名 simpleMethod为方法名
// 设置返回值类型
// Class[] returnTypes = new Class[] {String.class};
// 设置调用的参数
Object[] param = new Object[] {"client..."};//输入参数
// 调用服务,获得返回值
// serviceClient.invokeRobust(namespace, param);
Object[] b = serviceClient.invokeBlocking(namespace, param, new Class[]{String.class});
System.out.println(b[0]);
}
}
import javax.xml.namespace.QName;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;
public class Client {
public static void main(String[] args) throws Exception {
// ObjectFactory factory = new ObjectFactory();
// SimpleMethod method=factory.createSimpleMethod();
// System.out.println("client");
RPCServiceClient serviceClient;
serviceClient = new RPCServiceClient();
Options options = serviceClient.getOptions();
// 这一步指定了该服务的提供地址
EndpointReference targetEPR = new EndpointReference("http://localhost:8888/axis2/services/simpleServer?wsdl");
// 将option绑定到该服务地址
options.setTo(targetEPR);
// 添加具体要调用的方法,这个可以从该服务的wsdl文件中得知
// 第一个参数是该服务的targetNamespace,第二个为你所要调用
// 的operation名称
QName namespace = new QName("http://axis2", "simpleMethod");//axis2为服务端项目名 simpleMethod为方法名
// 设置返回值类型
// Class[] returnTypes = new Class[] {String.class};
// 设置调用的参数
Object[] param = new Object[] {"client..."};//输入参数
// 调用服务,获得返回值
// serviceClient.invokeRobust(namespace, param);
Object[] b = serviceClient.invokeBlocking(namespace, param, new Class[]{String.class});
System.out.println(b[0]);
}
}