Using Node to call SOAP Web Service over https

前端 未结 2 1514
不知归路
不知归路 2021-02-10 20:53

I am trying to use node-soap https://github.com/vpulim/node-soap to call a web service but I am having trouble using the module with https.

In the code

相关标签:
2条回答
  • 2021-02-10 21:27

    For recommended solution - Provide root/intermediate certificates of CA to verify the remote certificates, try this-

    var request = require('request'); 
    var specialRequest = request.defaults({ ca: fs.readFileSync('ca.cert.pem') //path of CA cert file );
    
    var auth = "Basic " + new Buffer.from("myUsername:myPassword").toString("base64"); 
    var options = { wsdl_headers: { Authorization: auth }, request: specialRequest };
    
    soap.createClient(url, options, function (err, client) {
        client.myFunction(args, function (err, result) { 
            console.log(result);
        });
    });
    
    0 讨论(0)
  • 2021-02-10 21:45

    As cleared from tls specific error, you aren't able to create soap client by invoking soap.createClient. It is returning err and undefined client, that's why subsequent calls are failing.

    The main reason behind the certificate issue can be either soap server certificates are signed by internal CA or soap server is using self-signed certificate.

    Possible solutions that can be used to tackle the issue are

    1. [ Not recommended ] Ignore certificate specific warnings by disabling SSL check at request time. e.g.

      var request = require('request');
      var specialRequest = request.defaults({
         strictSSL: false
      });
      
    2. [ Recommended ] Provide root/intermediate certificates of CA to verify the remote certificates.

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

    For both solutions, pass this specialRequest to createClient.

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

    I just went through the documentation and came up with the solution. It may or may not work, but worth trying logically. I couldn't test above-mentioned solutions, but it should work.

    Hope it helps you.

    0 讨论(0)
提交回复
热议问题