WebService 接口请求实例

test测试类:

public class test {
    public static void main(String[] args) throws Exception {
        //测试调用WebService
        String url="http://127.0.0.1:8006/WmsWebServiceImpl?wsdl";
        String namespace="http://WMSService/wsdl";
        String methodName="updateInPlanInfo";
        Map<String, String> params=new HashMap<>();
        params.put("param","{\n" +
                "  \"data\": [\n" +
                "    {\n" +
                "      \"lineId\": \"1\",\n" +
                "      \"materialCode\": \"123\",\n" +
                "      \"batch\": \"1\",\n" +
                "      \"status\": \"良品\",\n" +
                "      \"quantity\": 1.0,\n" +
                "      \"companyCode\": \"12321\",\n" +
                "      \"produceDate\": \"2022-07-04 17:49:46\"\n" +
                "    }\n" +
                "  ],\n" +
                "  \"planCode\": \"JD20220704174946\",\n" +
                "  \"type\": \"入库\"\n" +
                "}");

        WebServiceUtils.call(url,namespace,methodName,params);
    }
}

说明:

1、url为调用webservice 地址

2、namespace为命名空间

3、methodName为函数名称也就是接口名称

4、params为请求参数其中类型可自己定义。

5、WebServiceUtils.call为WebService工具类

   log.info("调用 WebService 发送参数==>" +test);
    log.info("调用 WebService 调用地址==>" + url);
    log.info("调用 WebService 函数名==>" + methodName);
    log.info("调用 WebService 命名空间==>" + namespace);

    String soapActionURI = namespace + methodName;
    try {
        Service service = new Service();

        SOAPHeaderElement header = new SOAPHeaderElement(namespace, methodName);
        header.setNamespaceURI(namespace);

        Call call = (Call) service.createCall();
        call.setTargetEndpointAddress(url);

        call.setOperationName(new QName(namespace, methodName));

        // 添加参数
        List<String> parameterList = Lists.newArrayList();
        if (outPlanId != null) {


                parameterList.add(outPlanId);
                parameterList.add(processStatus);

        }
        call.setUseSOAPAction(true);
        call.setSOAPActionURI(soapActionURI);
        call.addHeader(header);
        // 设置返回类型
        call.setReturnType(XMLType.XSD_SCHEMA);
        // 接口返回结果
        Schema schemaResult = (Schema)call.invoke(parameterList.toArray());
        String result = "";
        for(int i = 0; i<schemaResult.get_any().length; i++){
            result = result + schemaResult.get_any()[i];
        }
        log.error("调用 WebService 接口返回===>" + result);
        return result;
    } catch (Exception e) {
        log.error("调用 WebService 接口错误信息==>" + e.getMessage());
    }
    return null;
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值