2

I'm trying to make a SOAP request to external API using node-soap. The Root element inside Body is taken from WSDL schema. Is it possible to change it somehow before request?

Here's the client creation and request sending:

let client = await soap.createClientAsync(wsdl, soapClientOptions);
let result = await client.MakeCalculationAsync({});
console.log(result);

XML produced by node-soap is:

<soap:Body>
    <IIntegrationService_MakeCalculation_InputMessage> 
    </IIntegrationService_MakeCalculation_InputMessage>
</soap:Body>

But the root element should be <MakeCalculation>, not <IIntegrationService_MakeCalculation_InputMessage>, cause in last case the response results in an error.

I found some workaround which is quite dodgy in my opinion. You can use postProcess method to replace text in xml like this:

client.MakeCalculation({}, (err, result, rawResponse, soapHeader, rawRequest) => {
            console.log(result);
          }, {
            postProcess: (_xml) => {
              return _xml
.replace('IIntegrationService_MakeCalculation_InputMessage', 'MakeCalculation')
.replace('/IIntegrationService_MakeCalculation_InputMessage', '/MakeCalculation');
            }
          }
        );

But as I said it's not a good way and you can't use it in Async way as well.

P.S. There was very similar question here How can I configure the Root Element of a node-soap request body? But still no awnsers.

dvnev
  • 121
  • 8

0 Answers0