如何在NodesJS中从Lambda调用现有的Soap API服务

问题描述 投票:0回答:1

我们在AWS中有一个lamdbda设置,用NodeJS / Javascript编写。

我们在dotnet中已有一个SOAP服务,我们希望从nodejs函数中调用它。

我曾尝试使用node-soap,但不确定如何与现有服务一起使用。

var url =
    "PATH TO WSDL";
  var args = { name: "value" };
  console.log("call soap");
  await soap
    .createClientAsync(url)
    .then(client => {
      console.log("client");
      console.log(client);
      return client
        .TestFunction({ name: "value" })
        .then(result => {
          console.log("result");
          console.log(result);
        })
        .catch(error => {
          console.log("catch error");
          console.log(error);
        });
    })
    .catch(error => {
      console.log("catch create error");
      console.log(error);
    }); 

我似乎遇到了catch创建错误,但它似乎抱怨上面的.then。

TypeError: Cannot read property 'then' of undefined

对于上面的示例,“ TestFunction”是SOAP API中存在的端点的名称。

为了在邮递员中测试此SOAP API,我简单地创建了.asmx URL的帖子,并带有特定格式的文档。有没有办法在节点上做同样的事情?

其他上下文基本上,我们有一个lambda函数,它以下列方式流动...

module.exports.downloadSomething = async (event, context, callback) => {
    // async lambda function... 
    ... some validation
    await getSomeSecretValue().catch(error => {
        ... handle error
    });
    return startApiCall();
}

function startApiCall() {
    ... generates some hash
    return callSoap();
}

let callSoap = () => {
 var url =
    "PATH TO WSDL";
  var args = { name: "value" };
  soap
    .createClientAsync(url)
    .then(client => {
      client
        .TestFunction({ name: "value" })
        .then(result => {
          console.log("result");
          console.log(result);
        })
        .catch(error => {
          console.log("catch error");
          console.log(error);
        });
    })
    .catch(error => {
      console.log("catch create error");
      console.log(error);
    }); 
}

目前,以上只是注销了“通话肥皂”并结束了请求,该请求不会继续进行。和/或lambda在完成之前完成。

javascript node.js soap soap-client node-soap
1个回答
0
投票

简短回答:

删除awaitreturn,因此您的代码如下所示:(为了简洁起见,删除了控制台日志)

var url =
    "PATH TO WSDL";
  var args = { name: "value" };
  soap
    .createClientAsync(url)
    .then(client => {
      client
        .TestFunction({ name: "value" })
        .then(result => {
          console.log("result");
          console.log(result);
        })
        .catch(error => {
          console.log("catch error");
          console.log(error);
        });
    })
    .catch(error => {
      console.log("catch create error");
      console.log(error);
    }); 

长回答:

在没有更多上下文的情况下,我最好的猜测是问题出在您使用await上。首先,await仅可用于标有async的功能。其次,您不需要同时使用then() awaitMore on async/await

接下来,您不需要async呼叫await。这可能是导致捕获创建错误的原因。

我希望这会有所帮助!

© www.soinside.com 2019 - 2024. All rights reserved.