0

I'm using the npm soap package to work with a soap webservice.

Apparently it's the most widely used soap client in the Node.JS ecosystem, and I'm working with a fairly mature commercial webservice, so I don't know who's "wrong" (or non standard compliant), but I have an issue with xmlns attribute in the xml tag of the method I'm calling.

We generate requests like this:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:tns="https://webservice.com"
    xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/">
    <soap:Body>
        <MethodName xmlns="https://webservice.com">
        .......
        </MethodName>
    </soap:Body>
</soap:Envelope>

But the server rejects this, because it's expecting just <MethodName> and not <MethodName xmlns="...">. How can I remove this attribute from the request ? Ideally through options passed to the client, but I'm also open to using another soap client.

I can also use a plain http client and build xml manually, but I'm looking for a higher-level alternative if possible.

3 Answers 3

1

Apparently, strong-soap is a rewrite or at least has a similar API so soap and although it has less monthly downloads, it has a stronger community (judging by activity on their respective support/community chats) and it doesn't inject the xmlns attribute in the method tag.

So if anyone else is stuck with soap, give strong-soap a try !

Sign up to request clarification or add additional context in comments.

Comments

1

It's happened the same to me, cause node-soap add by default a xmlns inside the envelope and I need to replace. Finally I found a solution, maybe not the best, but could be usseful for someone.

You can override the data that you send on your request, so you can replace whatever you want, included the envelope.

You have the possibility to includ options (object) when the method it´s called:

Client.method(args, callback, options)

include this object like options:

{
    transformRequest: [
        function (data, headers) {
            return data.replace(
               `xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"`,
                ``
            );
        },
    ],
}

Finally the calling to method looks like this:

client[method](
    params,
    function (err, result) {
        if (err) console.log(err, "<<<<<ERROR");
        else console.log(result);
    }, {
        transformRequest: [
            function (data, headers) {
                return data.replace(
                  `xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"`,
                  ``
                );
            },
        ],
    }
)

With this you override the data. I hope will be useful for someone who needs to change the envelope created by default.

Comments

0

The other answer from @Charly https://stackoverflow.com/a/72039697/990642 using transformRequest didn't work for me, the request would hang and I couldn't isolate why. I didn't evaluate strong-soap as a replacement.

Instead I used postProcess like so:

client[method](
  params,
  (err, result) => {
    // callback...
  },
  {
    postProcess: (xml: string) => {
      return xml.replace(
        '<MethodName xmlns="https://webservice.com">',
        '<MethodName>'
      );
    },
  }
)

Where xml is the HTTP request body and you can perform any manipulations you want on that string.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.