SoapUtil.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package com.uas.eis.sdk.webservice;
  2. import com.uas.eis.sdk.dto.SubPickmtrlReq;
  3. import net.sf.json.JSONObject;
  4. import org.apache.axis.client.Call;
  5. import org.apache.axis.client.Service;
  6. import org.apache.axis.encoding.XMLType;
  7. import org.apache.axis.message.SOAPHeaderElement;
  8. import org.apache.axis.soap.SOAPConstants;
  9. import javax.xml.namespace.QName;
  10. import javax.xml.rpc.ParameterMode;
  11. import javax.xml.soap.SOAPElement;
  12. import javax.xml.soap.SOAPException;
  13. import java.io.IOException;
  14. import java.util.ArrayList;
  15. import java.util.List;
  16. /**
  17. * @author: zhouy
  18. * @date: 2021/10/15 14:46
  19. * @desc: WebService 请求工具类
  20. * POST /MES/mes_k3.asmx HTTP/1.1
  21. * Host: 183.62.131.97
  22. * Content-Type: text/xml; charset=utf-8
  23. * Content-Length: length
  24. * SOAPAction: "http://tempuri.org/MES_K3"
  25. *
  26. */
  27. public class SoapUtil {
  28. public static void main(String[] args) throws IOException {
  29. callWebserviceASMX();
  30. }
  31. public static void callWebserviceASMX() throws IOException {
  32. //获取webservice接口地址
  33. String url = "http://183.62.131.97:9880/MES/mes_k3.asmx";
  34. //获取域名地址,server定义的,一般默认是http://tempuri.org/,如果不对,找对方索要
  35. String soapaction = "http://tempuri.org/";
  36. String method = "MES_K3";
  37. Service service = new Service();
  38. String result = "";
  39. try {
  40. Call call = (Call) service.createCall();
  41. call.setTargetEndpointAddress(url);
  42. call.addHeader(initSOAPHeaderElement());
  43. //设置要调用的方法
  44. call.setOperationName(new QName(soapaction, method));
  45. call.addParameter(new QName(soapaction, "type"), XMLType.XSD_STRING, ParameterMode.IN);
  46. call.addParameter(new QName(soapaction, "data"), XMLType.XSD_ENTITY, ParameterMode.IN);
  47. call.setEncodingStyle(null);
  48. //设置要返回的数据类型(标准的类型)
  49. call.setReturnType(XMLType.XSD_STRING);
  50. call.setUseSOAPAction(true);
  51. call.setSOAPVersion(SOAPConstants.SOAP12_CONSTANTS);
  52. call.setSOAPActionURI(soapaction + method);
  53. call.setEncodingStyle("GB2312");
  54. //调用方法并传递参数
  55. String type = "SUB_PICKMTRL";
  56. SubPickmtrlReq req = new SubPickmtrlReq();
  57. req.setSUPPLIERNO("D.02.008");
  58. List<SubPickmtrlReq.SubPickmtrlENTRY> entryList = new ArrayList<SubPickmtrlReq.SubPickmtrlENTRY>();
  59. SubPickmtrlReq.SubPickmtrlENTRY entry = new SubPickmtrlReq.SubPickmtrlENTRY();
  60. entry.setENTRY_FNUMBER("01.EC0.3R3C201H10A");
  61. entry.setENTRY_Unitno("Pcs");
  62. entry.setENTRY_FActualQty(30);
  63. entry.setENTRY_StockNO("20.01");
  64. entry.setENTRY_ParentNO("02.PMA.D1C8192B003");
  65. entry.setENTRY_FSrcInterId((long)147784);
  66. entry.setENTRY_FSrcInterId((long)147784);
  67. entry.setENTRY_FSrcEntryId((long)4860434);
  68. entry.setENTRY_FSubReqId((long)127323) ;
  69. entry.setENTRY_FSRCBIZENTRYID((long)138737) ;
  70. entry.setENTRY_FSubReqEntryId((long)138737) ;
  71. entry.setENTRY_FPPbomBillNo("SUBBOM00035139");
  72. entry.setENTRY_FPOOrderBillNo("P202109160004");
  73. entry.setENTRY_FPOOrderSeq(2);
  74. entry.setENTRY_FSubReqEntrySeq(1);
  75. entry.setENTRY_FSUBREQBILLNO("W20210916023");
  76. entry.setENTRY_FSRCENTRYSEQ(1);
  77. entryList.add(entry);
  78. req.setENTRY(entryList);
  79. } catch (Exception e) {
  80. e.printStackTrace();
  81. }
  82. }
  83. private static SOAPHeaderElement initSOAPHeaderElement(){
  84. SOAPHeaderElement soapHeaderElement = new SOAPHeaderElement(new QName("http://tempuri.org/","UserValidationSoapHeader"));
  85. try {
  86. SOAPElement element = soapHeaderElement.addChildElement("UserName");
  87. element.addTextNode("YR_MES");
  88. element = soapHeaderElement.addChildElement("Password");
  89. element.addTextNode("YR_MES!#%123");
  90. return soapHeaderElement;
  91. } catch (SOAPException e) {
  92. e.printStackTrace();
  93. }
  94. return null;
  95. }
  96. }