• Java测试调用.net 接口服务


    package com.karros.test;
    
    import java.util.HashMap;
    import java.util.Map;
    
    import javax.xml.namespace.QName;
    
    import org.apache.axis.client.Call;
    import org.apache.commons.lang.StringUtils;
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    
    public class TestWsdl {
    
        protected final Log logger = LogFactory.getLog(getClass());
        public static void main(String[] args) throws Exception {   
            Map<String, Object> paramMap = new HashMap<String, Object>();
            paramMap.put("syncTime", "20200401");
            Map<String, Object> resultMap = new HashMap<String, Object>();
            TestWsdl aa = new TestWsdl();
            resultMap= aa.getWebService(paramMap);
            System.out.println(resultMap);
        } 
    
    //    @Value("${weixin_sign_url}")
    //    private String endpoint;
        //  #微信签到云平台接口地址
        // weixin_sign_url=http://10.182.5.173:1111/Service/WXQDService.asmx
        
        public String endpoint = "http://10.182.5.96:102/Service/ORGService.asmx";
        public Map<String, Object> getWebService(Map<String, Object> paramMap) throws Exception {
            logger.debug("获取接口开始...");
            Map<String, Object> resultMap = new HashMap<String, Object>();
            resultMap.put("success", true);
            try {
                String syncTime = (String) paramMap.get("syncTime");
                if (StringUtils.isBlank(syncTime)) {    //20200401
                    resultMap.put("success", false);
                    return resultMap;
                } else {
                    // 创建一个服务(service)调用(call)
                    org.apache.axis.client.Service service = new org.apache.axis.client.Service();
                    Call call = (Call) service.createCall();// 通过service创建call对象
                    // 设置service所在URL
                    call.setTargetEndpointAddress(new java.net.URL(endpoint));
    
                    call.setOperationName(new QName("http://tempuri.org/", "GetUserList"));
                    // .net 那边的方法 "http://tempuri.org/"这个也要注意Namespace的地址,不带也会报错
                    call.addParameter(new QName("http://tempuri.org/", "syncTime"), org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
    
                    call.setUseSOAPAction(true);
                    call.setReturnType(org.apache.axis.encoding.XMLType.SOAP_STRING); // 返回参数的类型
                    call.setSOAPActionURI("http://tempuri.org/GetUserList"); // 这个也要注意
                    String userVo = (String) call.invoke(new Object[] { syncTime });
                    if (StringUtils.isBlank(userVo) || StringUtils.equals("[]", userVo)) {
                        resultMap.put("success", false);
                    } else {
                        resultMap.put("userVo", userVo);
                    }
                }
            } catch (Exception e) {
                resultMap.put("success", false);
                logger.error("获取信息异常", e);
            }
            logger.debug("获取接口结束...");
            return resultMap;
        }
    
    }

    基础:https://www.cnblogs.com/herizai/p/6957611.html

    package com.karros.test;
    import java.util.HashMap;import java.util.Map;
    import javax.xml.namespace.QName;
    import org.apache.axis.client.Call;import org.apache.commons.lang.StringUtils;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;
    public class TestWsdl {
    protected final Log logger = LogFactory.getLog(getClass());public static void main(String[] args) throws Exception {   Map<String, Object> paramMap = new HashMap<String, Object>();paramMap.put("syncTime", "20200401");Map<String, Object> resultMap = new HashMap<String, Object>();TestWsdl aa = new TestWsdl();resultMap= aa.getWebService(paramMap);System.out.println(resultMap);} 
    //@Value("${weixin_sign_url}")//private String endpoint;//  #微信签到云平台接口地址// weixin_sign_url=http://10.182.5.173:1111/Service/WXQDService.asmxpublic String endpoint = "http://10.182.5.96:102/Service/ORGService.asmx";public Map<String, Object> getWebService(Map<String, Object> paramMap) throws Exception {logger.debug("获取接口开始...");Map<String, Object> resultMap = new HashMap<String, Object>();resultMap.put("success", true);try {String syncTime = (String) paramMap.get("syncTime");if (StringUtils.isBlank(syncTime)) {//20200401resultMap.put("success", false);return resultMap;} else {// 创建一个服务(service)调用(call)org.apache.axis.client.Service service = new org.apache.axis.client.Service();Call call = (Call) service.createCall();// 通过service创建call对象// 设置service所在URLcall.setTargetEndpointAddress(new java.net.URL(endpoint));
    call.setOperationName(new QName("http://tempuri.org/", "GetUserList"));// .net 那边的方法 "http://tempuri.org/"这个也要注意Namespace的地址,不带也会报错call.addParameter(new QName("http://tempuri.org/", "syncTime"), org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
    call.setUseSOAPAction(true);call.setReturnType(org.apache.axis.encoding.XMLType.SOAP_STRING); // 返回参数的类型call.setSOAPActionURI("http://tempuri.org/GetUserList"); // 这个也要注意String userVo = (String) call.invoke(new Object[] { syncTime });if (StringUtils.isBlank(userVo) || StringUtils.equals("[]", userVo)) {resultMap.put("success", false);} else {resultMap.put("userVo", userVo);}}} catch (Exception e) {resultMap.put("success", false);logger.error("获取信息异常", e);}logger.debug("获取接口结束...");return resultMap;}
    }

  • 相关阅读:
    如何系统收集网页/电子书等相关的知识点
    针式PKM软件多个版本兼容功能的应用
    软件开发出路:做精某一卖点!
    深入针式PKM应用系列(1) 虚拟文件夹功能,让文件想放哪就放哪
    PKM软件:提供知识应用的工具支持
    解决长串英文字母显示不能自动换行的问题
    C#中判断字符串A中是否包含字符串B
    小技巧锦集
    解决Notes的"The remote server is not a known tcp/IP host"问题的方法
    将Sql Server自增长字段的目前识别值重调!
  • 原文地址:https://www.cnblogs.com/tldxh/p/12612047.html
Copyright © 2020-2023  润新知