Node.js具有复杂类型的SOAP调用

Vin*_*ano 5 soap soap-client node.js

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

当我检查WSDL时,我注意到服务器调用需要ComplexType参数.有没有办法创建我需要的ComplexTypes,或者我可以只使用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);
          }
      });
Run Code Online (Sandbox Code Playgroud)

});

小智 1

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

\n\n

此示例使用 Cyber​​Source API 的 wsdl

\n\n
<data:requestMessage xmlns:data="urn:schemas-cybersource-com:transaction-data-1.93" xmlns="urn:schemas-cybersource-com:transaction-data-1.93">\n\n  <data:merchantAuthentication>\n    <data:name>285tUPuS</data:name>\n    <data:transactionKey>58JKJ4T95uee75wd</data:transactionKey>\n  </data:merchantAuthentication>\n\n</data:requestMessage>\n
Run Code Online (Sandbox Code Playgroud)\n\n

另外,我不\xe2\x80\x99t确切地知道Authorize.net api是如何工作的,但听起来你可能想在必要时使用用户名令牌身份验证进行检查:

\n\n
client.setSecurity(new soap.WSSecurity(\'username\xe2\x80\x99, \xe2\x80\x98password\xe2\x80\x99));\n
Run Code Online (Sandbox Code Playgroud)\n