使用复杂types的Node.js SOAP调用

我目前正在尝试使用node-soap ( https://github.com/milewise/node-soap )来调用Authorize.net的SOAP服务器。 但是,我似乎无法让我的客户端代码传递适当的参数。 我知道该函数正在调用服务器,因为我得到一个服务器错误响应。

当我检查WSDL时,我注意到服务器调用需要ComplexType参数。 有没有办法来创build我需要的复杂types,或者我可以只使用Javascript对象? 这是我现在的代码:

var soap = require('soap'); var url = 'https://api.authorize.net/soap/v1/Service.asmx?WSDL'; soap.createClient(url, function(err, client) { var args = { merchantAuthentication: { name: '285tUPuS', transactionKey: '58JKJ4T95uee75wd' } }; client.Service.ServiceSoap12.GetTransactionDetails(args, function(err, result) { if (err) { console.log(err); } else { console.log(result.GetTransactionDetailsResult[0].messages); } }); 

});

在将事务发送到服务器之前,node-soap模块将您的JavaScript对象转换为XML。 它将请求包装在wsdl所概述的xml元素中。 下面是node-soap在传递提供的对象时可能产生的一个例子(重要的是注意外部元素是由node-soap模块根据wsdl创build的):

这个例子使用wsdl作为Cyber​​Source API

 <data:requestMessage xmlns:data="urn:schemas-cybersource-com:transaction-data-1.93" xmlns="urn:schemas-cybersource-com:transaction-data-1.93"> <data:merchantAuthentication> <data:name>285tUPuS</data:name> <data:transactionKey>58JKJ4T95uee75wd</data:transactionKey> </data:merchantAuthentication> </data:requestMessage> 

另外,我不确切知道Authorize.net api是如何工作的,但是如果有必要的话,您可能会想要使用用户名令牌authentication:

 client.setSecurity(new soap.WSSecurity('username', 'password'));