RPC调用webservice接口
maven支持包:
org.apache.axis axis 1.4
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;
public static void main(String[] args) {
try {
//接口地址
String endpoint = "http://192.168.0.111:10086/webServices/xxxwebServices";
//webservice接口的namespace
String targetNamespace = "http://namespace.com";
// 直接引用远程的wsdl文件
// 以下都是套路
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint));
// WSDL里面描述的接口名称
call.setOperationName(new QName(targetNamespace, "interfaceName"));
//这里是我的业务xml参数列表,可以根据自己的情况,修改这个方法。
String businessSystemOnlineNum = getXml("306699", "2022-07-08 11:00:00", "xxxxxxx");
//打印下
System.out.println("businessSystemOnlineNum=" + businessSystemOnlineNum);
//param为webservice中接口的参数名
call.addParameter("param",
org.apache.axis.encoding.XMLType.XSD_DATE,
javax.xml.rpc.ParameterMode.IN);// 接口的参数
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);// 设置返回类型
//businessSystemOnlineNum为构建的参数
String result = (String) call.invoke(new Object[]{businessSystemOnlineNum});
// 给方法传递参数,并且调用方法
System.out.println("result is " + result);
} catch (Exception e) {
System.err.println(e.toString());
}
}
private static String getXml(String areaCode, String time, String apiName) {
StringBuffer str = new StringBuffer();
//固定头
str.append("");
//参数的列表根据业务设定,来自己修改。
//str.append("");
//str.append("");
//str.append(areaCode);
//str.append(" ");
//str.append("");
//str.append("");
//str.append(" ");
return str.toString();
}



