java 使用AXIS調用遠程的web service


  1、服務

    

 

  2、代碼

import javax.xml.namespace.QName;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;

/**
 * @Author:
 * @Description:
 * @Date:Created in 10:11 2018/9/7
 * @Modified by:
 **/
public class accessWeb {
 
    public static void main(String args[]) {
        test();
    }

    public static void test() {
        String url = "http://15.23.25.21/spesvc/Ott/OttService.asmx";// 提供接口的地址
        String soapaction = "http://oc.ctrchina.cn/";// 域名,這是在server定義的
        String monitorDate = "2018-09-01";
        Service service = new Service();
        try {
            Call call = (Call) service.createCall();
            call.setTargetEndpointAddress(url);
            call.setOperationName(new QName(soapaction, "GetPlayListGuidWithDate")); // 設置要調用哪個方法
            call.addParameter(new QName(soapaction, "monitorDate"), // 設置要傳遞的參數
                    org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
            call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);// (標准的類型)
            call.setSOAPActionURI(soapaction + "GetPlayListGuidWithDate");
            String res = String.valueOf(call.invoke(new Object[] { monitorDate }));// 調用方法並傳遞參數
            System.out.println(res);

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }


}

  2、應用jar包

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM