使用Node-soap使用WSDL的问题

时间:2016-06-13 14:50:12

标签: node.js soap wsdl node-soap

见下文TL; DR!

使用node-soap消费WSDL时遇到问题。我已经尝试过使用其他WSDL(在网上找到的例子)并且它们工作得很好 - 但是,我遇到了无数问题。我正在使用soap-as-promised,它使用node-soap模块。它应该是无关紧要的。

var soap = require('soap-as-promised');
var url = 'https://test.ipg-online.com/ipgapi/services/order.wsdl';

var apiCall = exports.apiCall = function () {
        console.error("test");
        soap.createClient(url, { wsdl_options: { cert: '/path/to/cert.pem', key:'/path/to/key.key' } } )
        .then(function(client) {
            console.error(client);
            client.describe();
        })
        .catch(function(error) {
            console.error(error);
        });

    }

这是我现在使用的代码,但这肯定是不对的。它返回以下错误(我的证书和私钥的路径是正确的):

[错误:错误:0906D06C:PEM例程:PEM_read_bio:无起始行]

基于文档,似乎我应该使用client.setSecurity进行SSL通信:

    client.setSecurity(new soap.ClientSSLSecurity(
    '/path/to/key'
    , '/path/to/cert'
    , {/*default request options*/}
  ));

但是,如果我这样做,并忽略wsdl_options,则客户端在回调中返回为undefined,不允许我运行任何函数,包括setSecurity函数。我认为它必须是两者的结合,但我对于什么组合感到迷茫。

TL; DR 尝试使用node-soap来使用WSDL;此WSDL需要证书和私钥,以及使用用户名/密件的身份验证。使用node-soap进行此操作的过程是什么?我是否必须安装证书(我在CentOS上),然后以某种方式引用它们?

任何帮助都表示赞赏 - 如果您熟悉这个过程,即使是另一个图书馆,请填写!谢谢:))

编辑:修正了!对于遇到类似问题的其他人,代码如下:

soap.createClient(url, { wsdl_options: { cert: fs.readFileSync('/path/to/cert.pem'), key: fs.readFileSync('/path/to/key.key'), passphrase: 'password' } } )

0 个答案:

没有答案