Java调用C#WebService接口方式


package com.topinfo.zjsqjzii.webservice.service.txzkteco;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;

import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@org.springframework.stereotype.Service
public class TxWebServices {

    /**
     * 
     */
    public boolean d(String userId) {

        return true;
    }

    /*
    *批量下载某单位所有指纹人脸数据到数据库
     deptid : 单位ID
    * */
    public boolean a(String deptId) {

        return true;
    }

    /*

     * */
    public boolean b(String userId) {

        return true;
    }

    /*
     *c
        
     * */
    public String c(String kqip) {

        Map param = new HashMap();
        String c = exec("c",param);
        return c;
    }

    /*
     *f
       
     * */
    public boolean f(String deptId) {

        return true;
    }

    /*
     *g
       
     * */
    public boolean g(String deptId) {

        return true;
    }

    /*
     *h
       

     * */
    public boolean h(String userId) {

        return true;
    }

    private String url = "http://172.168.190.220:8080/TcWebServices.asmx?wsdl";//提供接口的地址
    private String soapaction = "http://tempuri.org/";   //域名,这是在server定义的

    public String exec(String method, Map<String, String> param) {


        Service service = new Service();
        try {
            Call call = (Call) service.createCall();
            call.setTargetEndpointAddress(url);
            call.setOperationName(new QName(soapaction, method)); //设置要调用哪个方法
            call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);//(标准的类型)
            call.setUseSOAPAction(true);
            call.setSOAPActionURI(soapaction + method);
            String[] params = {};
            if (param != null && param.size() > 0) {
                List<String> list = new ArrayList<>();
                for (String key : param.keySet()) {
                    call.addParameter(new QName(soapaction, key), org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN); //设置要传递的参数
                    list.add(param.get(key));
                }

                params = list.toArray(new String[list.size()]);

//            call.addParameter(new QName(soapaction, "EndDate"), //设置要传递的参数
//                    org.apache.axis.encoding.XMLType.XSD_STRING,
//                    javax.xml.rpc.ParameterMode.IN);
//            call.setReturnType(new QName(soapaction, "GetAdmOrgUnitByUpdateTime"), Vector.class); //要返回的数据类型(自定义类型)

            }
            String v = (String) call.invoke(params);//调用方法并传递参数
            System.out.println("result is " + v);
            return v;
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        return "";

    }

    public static void main(String[] args) {
        TxWebServices txWebServices = new TxWebServices();
        Map param = new HashMap();


        param.put("deptId","");
        String exec = txWebServices.exec("a",param);

        System.out.println(exec);
    }

}

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM