当前位置 : 主页 > 网页制作 > Nodejs >

webservice 调用方法

来源:互联网 收集:自由互联 发布时间:2021-06-24
/** * Project Name:pvbdp-model-config * File Name:WsUtil.java * Package Name:com.iflytek.pvbdp.model.config.utils * Date:2016年11月4日下午7:59:30 * Copyright (c) 2016, hxyu@iflytek.com All Rights Reserved. **/package com.iflytek.pvbdp.

/**
 * Project Name:pvbdp-model-config
 * File Name:WsUtil.java
 * Package Name:com.iflytek.pvbdp.model.config.utils
 * Date:2016年11月4日下午7:59:30
 * Copyright (c) 2016, hxyu@iflytek.com All Rights Reserved.
 *
*/

package com.iflytek.pvbdp.face.client.utils;



import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.xml.namespace.QName;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * Date:     2016年11月4日 下午7:59:30   
 * @author   aoliu
 * @version  
 * @since    JDK 1.6
 */
public class WsUtil {
    
    private static Log log = LogFactory.getLog(WsUtil.class);
    
    
    public static String invokeyzt(String wsdl, String namespace,String method,Map<String,Object> paramMap) {
        String resultMsg = null;
        try {
            List<Object> paramValueList = new ArrayList<Object>();
            
            Service service = new Service();
            Call call =  (Call) service.createCall();
            call.setTargetEndpointAddress(wsdl);
            call.setOperationName(new QName(namespace,method));//WSDL里面描述的接口名称
            //设置参数
            Set<String> keyset =  paramMap.keySet();
            if(keyset.size()>0){
                for (String key : keyset) {
                    call.addParameter(key, org.apache.axis.encoding.XMLType.XSD_STRING,
                            javax.xml.rpc.ParameterMode.IN);//接口的参数
                    paramValueList.add(paramMap.get(key));
                    log.info("尝试使用JAVA WebService调用方法\n调用参数:\n[wsdl:" + wsdl + "]\n["+key+":  " +paramMap.get(key) + "]");
                }
            }
            
            Object [] objArr =    paramValueList.toArray(new Object[paramValueList.size()]);
            call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);//设置返回类型
            //设置参数值
            resultMsg = (String)call.invoke(objArr);
            log.info("使用JAVA WebService 调用方法调用成功=========================\n返回报文:\n" + resultMsg);
        }catch (Exception e){
            log.info("使用JAVA WebService调用方法异常!\n[异常信息]:"+e);
            e.printStackTrace();
        }finally {
            return resultMsg;
        }
    }

}


主要pom 

<dependency>
        <groupId>org.apache.axis</groupId>
        <artifactId>axis</artifactId>
        <version>1.4</version>
    </dependency>
    <dependency>
        <groupId>wsdl4j</groupId>
        <artifactId>wsdl4j</artifactId>
        <version>1.6.1</version>
    </dependency>
网友评论