我们在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在完成之前完成。
简短回答:
删除await
和return
,因此您的代码如下所示:(为了简洁起见,删除了控制台日志)
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()
和 await
。 More on async
/await
接下来,您不需要async
呼叫await
。这可能是导致捕获创建错误的原因。
我希望这会有所帮助!