Java test call .net interface services

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", to false );
                 return The resultMap; 
            } the else {
                 // create a service (-Service) call (Call) 
                org.apache.axis.client.Service-Service = new new org.apache.axis.client.Service (); 
                Call Call = (Call ) Service.createCall (); // create the call object through the service
                 // set the service where the URL of 
                call.setTargetEndpointAddress ( new new java.net.URL (Endpoint)); 

                call.setOperationName ( new new QName ( "http://tempuri.org / "," GetUserList " ));
                 // .NET there method"http://tempuri.org/ "This also pay attention to the address Namespace, without also being given 
                call.addParameter ( new new (QName" http://tempuri.org/ "," syncTime " ), the org.apache.axis .encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN); 

                call.setUseSOAPAction ( to true ); 
                call.setReturnType (org.apache.axis.encoding.XMLType.SOAP_STRING); // return parameter type 
                call. setSOAPActionURI ( "http://tempuri.org/GetUserList"); // this should also note 
                String userVo = (String) Call.invoke ( new new Object [] {} syncTime);
                 IF (StringUtils.isBlank (userVo) || StringUtils.equals ( "[]", UserVo)) { 
                    resultMap.put ( "Success", to false ); 
                } the else { 
                    resultMap.put ( "userVo" , userVo); 
                } 
            } 
        } the catch (Exception E) { 
            resultMap.put ( "Success", to false ); 
            logger.error ( "abnormal access to information" , E); 
        } 
        logger.debug ( "Get Interface end ..." );
         return The resultMap; 
    } 

}

Basis: 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; // # sign micro-channel interface address internet cloud // 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 ( "get Interface beginning ...") ; 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 {// create a service (service) call (call) org.apache.axis.client.Service service = new org.apache.axis.client.Service (); Call call = (Call) service.createCall (); // create the call object through the service // set URLcall service is located.setTargetEndpointAddress(new java.net.URL(endpoint));
call.setOperationName (new QName ( "http://tempuri.org/" , "GetUserList")); // .net way over there "http://tempuri.org/" This also pay attention to the address Namespace, without also being given call.addParameter (new ( "http://tempuri.org/" QName , "syncTime"), org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN) ;
call.setUseSOAPAction (to true); call.setReturnType (org.apache.axis.encoding.XMLType.SOAP_STRING); // return parameter type call.setSOAPActionURI ( "http://tempuri.org/GetUserList"); // Note also that the 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 ( " Get information abnormality" , e);} logger.debug ( "Get Interface end ..."); return resultMap;}
}

 

Guess you like

Origin www.cnblogs.com/tldxh/p/12612047.html