引入相关依赖: <!-- webService--> ?<dependency> ? ? ? <groupId>org.springframework.boot</groupId> ? ? ? <artifactId>spring-boot-starter-web-services</artifactId> ? </dependency> ? <!-- CXF webservice --> ? <dependency> ? ? ? <groupId>org.apache.cxf</groupId> ? ? ? <artifactId>cxf-spring-boot-starter-jaxws</artifactId> ? ? ? <version>3.2.1</version> ? </dependency> ? <dependency> ? ? ? <groupId>org.apache.cxf</groupId> ? ? ? <artifactId>cxf-rt-transports-http</artifactId> ? ? ? <version>3.2.1</version> ? </dependency> 浏览webService提供的方法,确定入参顺序 直接在浏览器里面访问url,如下 //获取webservice接口地址 String endpoint = "http://cmes.huawei.com/hw_manufacture/MidLayer.asmx"; //获取域名地址,server定义的 String soapaction = "http://Auto.huawei.com.cn/"; //调用的方法名 String method = "Get_Info_Frmbarcode"; // 创建一个服务(service)调用(call) org.apache.axis.client.Service service = new org.apache.axis.client.Service(); // 创建一个服务(service)调用(call) org.apache.axis.client.Call call = (org.apache.axis.client.Call) service.createCall();// 通过service创建call对象 // 设置service所在URL call.setTargetEndpointAddress(endpoint); call.setOperationName(new QName(soapaction, method)); //设置参数及类型,与接口参数对应 call.addParameter(new QName(soapaction, "sTaskType"), org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN); call.addParameter(new QName(soapaction, "sImport"), org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN); call.setUseSOAPAction(true); call.setReturnType(org.apache.axis.encoding.XMLType.SOAP_STRING); //返回参数的类型 call.setSOAPActionURI(soapaction + method); //这个也要注意 就是要加上要调用的方法getStoreList,不然也会报错
//invoke调用方法并传递参数,获取XML String xmlStr = (String) call.invoke(new Object[]{"BarcodeRelationSend", getEnvelope(barcodeRelationVo)});
private String getEnvelope(BarcodeRelationVo item) { StringBuilder sb = new StringBuilder(); sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); sb.append("<BarcodeRelationSend>"); sb.append("<Import>"); sb.append("<PO>"+item.getPO()+"</PO>"); sb.append("<VendorID>"+item.getVENDORID()+"</VendorID>"); sb.append("<ORGID>"+item.getORGID()+"</ORGID>"); sb.append("<ItemCode>"+item.getITEMCODE()+"</ItemCode>"); sb.append("<Barcode>"+item.getBARCODE()+"</Barcode>"); sb.append("<SonBarcode>"+item.getSONBARCODE()+"</SonBarcode>"); sb.append("<SonItemCode>"+item.getSONITEMCODE()+"</SonItemCode>"); sb.append("<Quantity>"+item.getQUANTITY()+"</Quantity>"); sb.append("<Supplier></Supplier>"); sb.append("<Manufactory></Manufactory>"); sb.append("<UploadFlag>"+item.getUPLOADFLAG()+"</UploadFlag>"); sb.append("<CheckMessage></CheckMessage>"); sb.append("<CreatedBy>"+item.getCREATEDBY()+"</CreatedBy>"); sb.append("<CreatedDate>"+item.getCREATEDDATE()+"</CreatedDate>"); sb.append("<UpdatedBy></UpdatedBy>"); sb.append("<UpdatedDate></UpdatedDate>"); sb.append("<Segment1>"+item.getSEGMENT1()+"</Segment1>"); sb.append("<Segment2>"+item.getSEGMENT2()+"</Segment2>"); sb.append("<Segment3></Segment3>"); sb.append("<Segment4></Segment4>"); sb.append("<Segment5></Segment5>"); sb.append("<Segment6></Segment6>"); sb.append("<Segment7></Segment7>"); sb.append("<ItemID></ItemID>"); sb.append("<SonItemID></SonItemID>"); sb.append("<CheckFlag></CheckFlag>"); sb.append("<EmsTransID>"+item.getEMSTRANSID()+"</EmsTransID>"); sb.append("<CheckInfo></CheckInfo>"); sb.append("<Segment8></Segment8>"); sb.append("<Segment9></Segment9>"); sb.append("<Segment10>"+item.getSEGMENT10()+"</Segment10>"); sb.append("<Segment11></Segment11>"); sb.append("<Segment12></Segment12>"); sb.append("<Segment13></Segment13>"); sb.append("<Segment14></Segment14>"); sb.append("<Segment15></Segment15>"); sb.append("</Import>"); sb.append("</BarcodeRelationSend>"); return sb.toString(); }