使用 Node 通过 https 调用 SOAP Web Service

mic*_*ger 4 soap node.js node-soap

我正在尝试使用 node-soap https://github.com/vpulim/node-soap来调用 Web 服务,但是我在使用带有https的模块时遇到了问题。

在下面的代码我使用HTTP,我可以看到的功能和日志describe()中的About功能。(响应为空,可能是因为在使用 http(?) 时 WS 是这样设置的)

var soap = require('soap');
var url = "http://XXXXX/service.svc?DocArchiveService/DocArchiveV201409";
var auth = "Basic " + new Buffer("USERXXX" + ":" + "PWYYY").toString("base64");

var args = {};

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

    console.log(client.describe().DocArchiveV201409.DocArchiveV201409Soap.About);

    client.DocArchiveV201409.DocArchiveV201409Soap.About(args, function(err, result){
        if (err) throw err;
        console.log(result);
    });
});
Run Code Online (Sandbox Code Playgroud)

输出:

{ input: {}, output: { AboutResult: 's:string' } }
Run Code Online (Sandbox Code Playgroud)

错误消息(这很好,因为无论如何响应都是空的):

错误:无法在完成时解析响应 (E:\Qlikview\SourceDocuments\UnderDevelopment\Node\node_modules\so ap\lib\client.js:383:19)

我的问题是,当使用 https 时,我得到了一个未定义的客户端。

E:\Qlikview\SourceDocuments\UnderDevelopment\Node\Soap.js:23 console.log(client); ^ ReferenceError: client is not defined at Object.anonymous (E:\Qlikview\SourceDocuments\UnderDevelopment\Node\Soa p.js:23:13)

有没有人在 https 中使用过 node-soap?

编辑: 由于下面的结果表明我需要先拥有证书。我试过在没有证书的情况下使用 SoapUI,效果很好。也许createClient我可以在 node-soap 中使用一些参数?

console.log(err) 返回:

{ Error: unable to get local issuer certificate
    at Error (native)
    at TLSSocket.<anonymous> (_tls_wrap.js:1079:38)
    at emitNone (events.js:86:13)
    at TLSSocket.emit (events.js:185:7)
    at TLSSocket._finishInit (_tls_wrap.js:603:8)
    at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:433:38) code: 'UNABLE_TO_GET_IS
SUER_CERT_LOCALLY' }
Run Code Online (Sandbox Code Playgroud)

Muk*_*rma 5

tls特定错误中清除后,您无法通过调用soap.createClient. 它正在返回errundefined客户端,这就是后续调用失败的原因。

certificate问题背后的主要原因可能是soap服务器证书由internal CA或soap服务器正在使用self-signed certificate

可用于解决该问题的可能解决方案是

  1. [ 不推荐 ] 通过SSL在请求时禁用检查来忽略证书特定警告。例如

    var request = require('request');
    var specialRequest = request.defaults({
       strictSSL: false
    });
    
    Run Code Online (Sandbox Code Playgroud)
  2. [推荐] 提供CA的根/中级证书来验证远程证书。

    var request = require('request');
    var specialRequest = request.defaults({
       agentOptions: {
          ca: fs.readFileSync('ca.cert.pem') //path of CA cert file
       }
    );
    
    Run Code Online (Sandbox Code Playgroud)

对于这两种解决方案,请将其传递specialRequestcreateClient.

    soap.createClient(url, { 
        wsdl_headers: {Authorization: auth},
        request : specialRequest
    }, function(err, client) {
        //your code
    });
Run Code Online (Sandbox Code Playgroud)

我刚刚浏览了文档并提出了解决方案。它可能有效也可能无效,但值得在逻辑上尝试。我无法测试上述解决方案,但它应该可以工作。

希望对你有帮助。