package com.demo.util;
import java.rmi.RemoteException;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.ServiceException;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
/**
* jar包 axis.jar 和 jaxrpc.jar 和commons-discovery-0.2.jar和wsdl4j.jar
*/
public class CaClient {
public String invokeRemoteFuc() {
String endpoint = "wsdl地址";
String result = "call failed!";
Service service = new Service();
Call call;
try {
call = (Call) service.createCall();
call.setTargetEndpointAddress(endpoint);
call.setOperationName(new QName("命名空间","方法名"));
// 设置参数名
call.addParameter("arg0", // 参数名
XMLType.XSD_STRING, // 参数类型:String
ParameterMode.IN); // 参数模式:'IN' or 'OUT'
call.addParameter("arg1",
XMLType.XSD_INT,
ParameterMode.IN);
call.addParameter("arg2",
XMLType.XSD_INT,
ParameterMode.IN);
// 设置返回值类型
call.setReturnType(XMLType.XSD_STRING); // 返回值类型:String
String arg0 = "abc2222";
String arg1 = "0";
String arg2 = "2017-12-28";
result = (String) call.invoke(new Object[] { arg0,arg1,arg2 });// (参数名必须是arg?)
} catch (ServiceException e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
}
return result;
}
// 测试
public static void main(String[] args) {
CaClient test = new CaClient();
String result = test.invokeRemoteFuc();
System.out.println(result);
}
}
import java.rmi.RemoteException;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.ServiceException;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
/**
* jar包 axis.jar 和 jaxrpc.jar 和commons-discovery-0.2.jar和wsdl4j.jar
*/
public class CaClient {
public String invokeRemoteFuc() {
String endpoint = "wsdl地址";
String result = "call failed!";
Service service = new Service();
Call call;
try {
call = (Call) service.createCall();
call.setTargetEndpointAddress(endpoint);
call.setOperationName(new QName("命名空间","方法名"));
// 设置参数名
call.addParameter("arg0", // 参数名
XMLType.XSD_STRING, // 参数类型:String
ParameterMode.IN); // 参数模式:'IN' or 'OUT'
call.addParameter("arg1",
XMLType.XSD_INT,
ParameterMode.IN);
call.addParameter("arg2",
XMLType.XSD_INT,
ParameterMode.IN);
// 设置返回值类型
call.setReturnType(XMLType.XSD_STRING); // 返回值类型:String
String arg0 = "abc2222";
String arg1 = "0";
String arg2 = "2017-12-28";
result = (String) call.invoke(new Object[] { arg0,arg1,arg2 });// (参数名必须是arg?)
} catch (ServiceException e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
}
return result;
}
// 测试
public static void main(String[] args) {
CaClient test = new CaClient();
String result = test.invokeRemoteFuc();
System.out.println(result);
}
}