'node soap remove xmlns attribute from method
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.
Solution 1:[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 !
Solution 2:[2]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Antoine |
Solution 2 | Tyler2P |