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