使用node-soap

时间:2017-11-28 12:04:48

标签: node.js xml soap soapui node-soap

我在发送肥皂请求方面遇到了一个相当恼人的问题。

如果我使用像SOAP-UI这样的工具,我可以轻松地在XML中构建一个合适的soap-request。 但如果我试图使用node-soap发送这个soap-request,我就无法获得正确的xml-string ...

我不知道为什么,但node-soap插件将字符串“SoapIn”附加到方法名称(GetArrBoardWithDetail)。请参阅以下代码段:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://thalesgroup.com/RTTI/2017-02-02/ldb/" xmlns:tok="http://thalesgroup.com/RTTI/2013-11-28/Token/types" xmlns:ct2007="http://thalesgroup.com/RTTI/2007-10-10/ldb/commontypes"
  xmlns:ct2015="http://thalesgroup.com/RTTI/2015-11-27/ldb/commontypes" xmlns:ldbt2017="http://thalesgroup.com/RTTI/2017-02-02/ldb/types">
  <soapenv:Header>
    <tok:AccessToken>
      <tok:TokenValue>asdf</tok:TokenValue>
    </tok:AccessToken>
  </soapenv:Header>
  <soapenv:Body>
    <tns:**GetArrBoardWithDetailsSoapIn**>
      <tns:numRows>50</tns:numRows>
      <tns:crs>ACY</tns:crs>
      <tns:filterCrs></tns:filterCrs>
      <tns:filterType>to</tns:filterType>
      <tns:timeOffset>0</tns:timeOffset>
      <tns:timeWindow>120</tns:timeWindow>
    </tns:**GetArrBoardWithDetailsSoapIn**>
  </soapenv:Body>
</soapenv:Envelope>

外部工具SoapUI不附加像“SoapIn”这样的字符串。 Soap UI附加字符串“Request”(请参阅​​以下代码段)。

<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://thalesgroup.com/RTTI/2017-02-02/ldb/" xmlns:tok="http://thalesgroup.com/RTTI/2013-11-28/Token/types" xmlns:ct2007="http://thalesgroup.com/RTTI/2007-10-10/ldb/commontypes"
  xmlns:ct2015="http://thalesgroup.com/RTTI/2015-11-27/ldb/commontypes" xmlns:ldbt2017="http://thalesgroup.com/RTTI/2017-02-02/ldb/types">
  <soapenv:Header>
    <tok:AccessToken>
      <tok:TokenValue>asdf</tok:TokenValue>
    </tok:AccessToken>
  </soapenv:Header>
  <soapenv:Body>
    <tns:**GetArrBoardWithDetailsRequest**>
      <tns:numRows>50</tns:numRows>
      <tns:crs>ACY</tns:crs>
      <tns:filterCrs></tns:filterCrs>
      <tns:filterType>to</tns:filterType>
      <tns:timeOffset>0</tns:timeOffset>
      <tns:timeWindow>120</tns:timeWindow>
    </tns:**GetArrBoardWithDetailsRequest**>
  </soapenv:Body>
</soapenv:Envelope>

Soap UI生成的请求正常工作。 有谁知道如何根据Soap-UI请求调整XML字符串的这一部分?

源代码:

soap.WSDL.prototype.ignoredNamespaces = ['targetNamespace', 'typedNamespace'];

// several options to modify the xml code of the soap request
const wsdlOptions = {
  envelopeKey: 'soapenv',
  'overrideRootElement': {
    'namespace': 'tns',
  }
};

// // creates the soapClient
soap.createClient(wsdlUrl, wsdlOptions, function(err, client) {

  // adds the needed SoapHeader to the requests
  client.addSoapHeader(soapHeaderXML);

  // specific soap-request
  client.GetArrBoardWithDetails(soapParams, function(result, err) {
    var lRequest = client.lastRequest;
    var prettyLRequest = prettyData.xml(lRequest);
    console.log(prettyLRequest);
    console.log(result);
  })
})

最基本的问候

1 个答案:

答案 0 :(得分:0)

您可以使用_xml文档中的node soap覆盖发送的soap正文。