jairochapela
jairochapela

Reputation: 38

How to fix "attribute xmlns:wsse invalid" error where calling SOAP web service in NodeJS using node-soap

I am trying to call a web service that requires authetication via X509 certificate. I'm using Node.js and node-soap module, getting successfully the WSDL.

But when I try to build the SOAP envelope with the Signature tag inside, I get the following error from the server:

The value of the attribute "prefix="xmlns",localpart="wsse",rawname="xmlns:wsse"" is invalid. Prefixed namespace bindings may not be empty.

I've tried to modify the existingPrefixes that are passed to the underlying library (xml-crypto).

This is my code:

var privateKey = fs.readFileSync(process.env.KEYFILE);
var publicKey = fs.readFileSync(process.env.CERTFILE);
var password = ''; // optional password
var options = {
  mustUnderstand: 1,
  signerOptions: {
    existingPrefixes: {
      'wsse': "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
    }
  }, 
};

var wsSecurity = new soap.WSSecurityCert(privateKey, publicKey, password, options);

const endpoint = process.env.ENDPOINT;

soap.createClientAsync(endpoint).then(client => {

    client.setSecurity(wsSecurity);

    return client.wiOperationAsync({ ... })
})

However, the error persists and I get a SOAP request body with something like this:

                <KeyInfo>
                    <wsse:SecurityTokenReference
                        xmlns:wsse="">
                        <wsse:Reference URI="#x509-1639ca80191641b9bd804497cfcef0b5" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"/>
                    </wsse:SecurityTokenReference>
                </KeyInfo>

Any idea to avoid that empty mlns:wsse attribute?

Upvotes: 1

Views: 300

Answers (0)

Related Questions