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; }