【问题标题】:Call SOAP request operation in Node.js在 Node.js 中调用 SOAP 请求操作
【发布时间】:2021-06-28 10:30:27
【问题描述】:

我正在尝试使用 node-soap 发出 SOAP 请求 - 我可以成功创建客户端,但是当我尝试调用 WSDL 中定义的操作时,它返回 undefined?这是我正确调用操作的方式吗?

const soap = require('soap');
const btoa = require('btoa');

response = {}
exports.getInventory = async (event, context) => {

    let username = '******';
    let password = '**********';

    let wsdlUrl = 'https://webservices.onewaybike.nl/CubeServices.svc?wsdl';

    const security = new soap.BasicAuthSecurity(username, password);

    let client = await soap.createClientAsync(wsdlUrl);
    client.setSecurity(security)
    
    let args = { Year: 2020}

    let dataResponse = await client.GetStockInfoNewOrdersForSeason(args)
    console.log(dataResponse)

    response = {
        statusCode: 200,
        body: "Inventory retrieved."
    };

    return response;
}

【问题讨论】:

    标签: node.js soap node-soap


    【解决方案1】:

    您必须使用Async 方法。
    Async 附加到方法 GetStockInfoNewOrdersForSeasonAsync

    let [dataResponse] = await client.GetStockInfoNewOrdersForSeasonAsync(args)
    

    响应是一个数组。 来自npm soap documentation

    Client.methodAsync(args, options) - 在 SOAP 服务上调用方法。

     client.MyFunctionAsync({name: 'value'}).then((result) => {
       // result is a javascript array containing result, rawResponse, soapheader, and rawRequest
       // result is a javascript object
       // rawResponse is the raw xml response string
       // soapHeader is the response soap header as a javascript object
       // rawRequest is the raw xml request string
     })
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-02-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-14
      • 1970-01-01
      • 2023-04-05
      • 2014-03-28
      • 1970-01-01
      相关资源
      最近更新 更多