how to set headers using node-soap in node.js

I am trying to consume a wsdl service and found node-soap, but I cannot find how to set some headers.

Example :

header = {
  "Username": "foo",
  "Password" : "bar"
}

The reason I need this is because the wsdl I am trying to consume requires the username and password via the headers.

Thanks in advance

Reading through the README for node-soap, if what you're trying to do is not WS-Security (I have no idea because I stay far away from SOAP), then you're going to have to file an issue with the author, because I see no way to set custom headers according to the documentation.

If it is WS-Security, then follow the instructions on this part of the README.

It may not be useful now however inorder to answering this question which is still open, here it goes.

You can make use of the method Client.addSoapHeader. As per the documentation

Client.addSoapHeader(soapHeader[, name, namespace, xmlns]) - add soapHeader to soap:Header node

Options

soapHeader Object({rootName: {name: "value"}}) or strict xml-string Optional parameters when first arg is object :

name Unknown parameter (it could just a empty string)

namespace prefix of xml namespace

xmlns URI

So you need to create an object and pass that to this method like:

var soapHeader = {
  "Username": "foo",
  "Password" : "bar"
};
client.addSoapHeader(soapHeader);

soap = require('soap')
parseString = require('xml2js').parseString

soap.createClient('https://api.bingads.microsoft.com/Api/Advertiser/AdIntelligence/v9/AdIntelligenceService.svc?wsdl', function(err, client) {
  var soapHeader = {
    'AuthenticationToken': process.argv[2],
    'DeveloperToken': process.argv[3],
    'CustomerId': process.argv[4],
    'CustomerAccountId': process.argv[5]
  };
  client.addSoapHeader(soapHeader);
  client.SuggestKeywordsFromExistingKeywords({Keywords: ["Hello world"]}, function(err, result) {
    console.log(result.body);
  });
});

This won't work. The reply is invalid login credentials. The same credentials work fine with SOAPUI. So, the format of sending the login credentials mentioned in the other answers must be wrong.