‘liusuyi’
2023-11-08 e020e16be81de6064bb8ead304529ae6b135dc59
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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<String , Object> 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 "";
        }
        
    }
 
}