Reputation: 569
I am using strong-soap (https://www.npmjs.com/package/strong-soap) for consuming wsdl from Node JS
I have a wsdl with header like below:-
<soapenv:Header>
<wsse:Security xmlns:wsse="http://xyz.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-24" xmlns:wsu="http://secure.xsd">
<wsse:Username>userid</wsse:Username>
<wsse:Password Type="http://pwdtext">password</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
I need to add this header information while creating client. I tried like
var url = "test?wsdl";
soap.createClient(url, {wsdl_headers: {"Username": "username","Password":"password"} }, function(err, client) {
//some logic
});
But every time I was getting soap fault "Authentication Failed".
Any idea what I am doing wrong?
Thanks in advance.
Upvotes: 1
Views: 6578
Reputation: 481
I had the same issue trying to pull data.
my mistake was that in the options of the createClient method is was using headers instead of wsdl_headers
also set the same authentication on the client before any method is called
my code looks as
var url = 'https://datahere?wsdl';
var httpOptions = {
wsdl_headers: {
'Authorization': 'Basic ' + new Buffer('username' + ':' + 'password').toString('base64')
}
};
soap.createClient(url, httpOptions, function(err, client) {
if (err) {
console.log(err.message);
response.status(401).end();
} else {
var requestArgs = {
Method1: 'dummyData',
Method2: ''
};
// client.setSecurity(new soap.BasicAuthSecurity('password', 'password'));
client.addHttpHeader('customHeader1', 'words');
client.addHttpHeader('Authorization', "Basic " + new Buffer('username-app-maker' + ':' + 'password').toString('base64'));
client.GETSOAPMETHOD(requestArgs, function(err, result) {
if (err) {
console.log(err.message);
}
console.log('i found ' + result);
response.send(result);
});
}
});
Upvotes: 4
Reputation: 792
As mentioned in this answer, wsdl_header object is expecting a key 'Authentication'
So try running the following code:
var url = 'test?wsdl';
var auth = "Basic " + new Buffer("your username" + ":" + "your password").toString("base64");
soap.createClient(url, { wsdl_headers: {Authorization: auth} }, function(err, client) {
});
Upvotes: 0