package com.ruoyi.utils.soap; import org.apache.axis.client.Call; import org.apache.axis.client.Service; import org.apache.axis.encoding.XMLType; import javax.xml.namespace.QName; import java.util.HashMap; import java.util.Map; /**设备健康接口 * 20221130 * zj * */ public class ARDSoapUtil { private static String url = "http://221.1.80.74:15024/ZX/ZX2WebService.asmx"; /**post方法获取数据 * String url , * **/ public static String postSoapResult(String url , String method ,Map map){ try { //字符集 String encodingStyle = "utf-8"; //WSDL的地址 String endpoint = url + "?wsdl"; //命名空间,在WSDL中对应的标签是:参见说明第3条 String targetNamespace = "http://tempuri.org/"; //具体方法的调用URI,在WSDL中对应的标签是:参见说明第4条 String soapActionURI = "http://tempuri.org/" + method; //具体调用的方法名,在WSDL中对应的标签是:参见说明第5条 Service service = new Service(); Call call = (Call) service.createCall(); call.setSOAPActionURI(soapActionURI); call.setTargetEndpointAddress(new java.net.URL(endpoint)); //设置目标接口的地址 call.setEncodingStyle(encodingStyle);//设置传入服务端的字符集格式如utf-8等 call.setOperationName(new QName(targetNamespace,method));// 具体调用的方法名,可以由接口提供方告诉你,也可以自己从WSDL中找 call.setUseSOAPAction(true); call.setReturnType(XMLType.XSD_STRING); Object[] o = new Object[map.size()]; int i=0; for (String key :map.keySet() ){ call.addParameter(new QName(targetNamespace , key), XMLType.XSD_INTEGER, javax.xml.rpc.ParameterMode.IN); o[i] = map.get(key); i++; } String result = (String) call.invoke(o); return result; } catch (Exception e) { e.printStackTrace(); return ""; } } }