节点soap,消费密码保护的WSDL

我正在尝试使用Node构build一个SOAP客户端,我使用“soap”包( https://www.npmjs.org/package/soap )尝试使用受用户/密码保护的WSDL。

在“soap.createClient”创build客户端之前,我找不到如何传递这些凭据,当然,如果我没有提供正确的凭据,我无法检索到WSDL。

我试过了:

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

然后调用“createClient”但无济于事。

另外,我试图用node-soap-client来完成这个工作,我可以通过这个客户端(显然)连接到WSDL,但是之后我不知道该怎么去(如何调用方法)。

我究竟做错了什么?

感谢你的帮助!

用户名和密码凭证可以像这样传递:

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) { }); 

(来自https://github.com/vpulim/node-soap/issues/56 ,谢谢你Gabriel Lucena https://github.com/glucena

当我将auth添加到头文件时,我仍然遇到了问题。 阅读代码和一些文章后,我发现这个工作。

 // 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})) }); });