Node soap, consume password protected WSDL

I am trying to create a SOAP client with Node, I am using the soap package ( https://www.npmjs.org/package/soap ) trying to use a user / password protected WSDL.

I cannot find how to transfer these credentials before creating the client using soap.createClient, and of course I cannot get the WSDL if I did not provide the correct credentials.

I tried:

soap.security.WSSecurity ('user', 'pass');

and then calling createClient, but to no avail.

In addition, I tried to do this using node-soap-client, with this client I (apparently) can connect to WSDL, but after that I have no idea where to go (like invoke).

What am I doing wrong?

Thank you for your help!

+4
source share
2 answers

User and password credentials can be transferred as follows:

var soap = require('soap');
var url = 'your WSDL url';
var auth = "Basic " + new Buffer("your username" + ":" + "your password").toString("base64");

soap.createClient(url, { wsdl_headers: {Authorization: auth} }, function(err, client) {
});

(obtained from https://github.com/vpulim/node-soap/issues/56 , thanks to Gabriel Lucen https://github.com/glucena )

+2
source

when I added auth to the headers, I still had a problem. After reading the code and several articles, I found this to work.

// or use local wsdl if security required
let url = 'http://service.asmx?wsdl' 
let wsdl = 'wsdl.wsdl';
let soap = require('soap');
let util = require('util')

soap.createClient(wsdl, function(err, client) {

    //don't forget to double slash the string or else the base64 will be incorrect
    client.setSecurity(new soap.BasicAuthSecurity('admin\\userName', 'password'));

    client.MethodFromWSDL(args, function (err, result) {
        console.log(util.inspect(result,{depth: null}))

    });
});
0
source

All Articles