/**
 * Copyright (C), 2015-2019
 * Author:   HJL
 * Date:     2019/11/11 13:21
 * Description:
 */
package com.emr.util;


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

public class test2 {
    public static final String url = "http://127.0.0.1/ToVideoWebService.asmx";

    public static void main(String[] args) {
        Object[] params = new Object[]{"stryang", 18};
        String result = sendWebservice( params, url);
        //System.out.println("===================");
        //System.out.println(result);
        //System.out.println(System.getProperty("user.dir"));

    }

    public static String sendWebservice(Object[] params, String url) {
        String soapaction = "http://tempuri.org/"; // 域名，这是在server定义的
        String operationName = "VideoWebService";// 调用方法名
        Service service = new Service();
        String ret = "";
        try {
            Call call = (Call) service.createCall();
            call.setTargetEndpointAddress(url);
            call.setOperationName(new QName(soapaction, operationName)); // 设置要调用哪个方法
            call.addParameter(new QName(soapaction, "name"), // 设置要传递的参数
                    org.apache.axis.encoding.XMLType.XSD_STRING,
                    javax.xml.rpc.ParameterMode.IN);
            call.addParameter(new QName(soapaction, "age"), // 设置要传递的参数
                    org.apache.axis.encoding.XMLType.XSD_STRING,
                    javax.xml.rpc.ParameterMode.IN);

            call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);// （标准的类型）
            call.setUseSOAPAction(true);
            call.setSOAPActionURI(soapaction + operationName);

            ret = (String) call.invoke(params);// 调用方法并传递参数

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



}



 

