如何解决在 Node.js 中调用 SOAP 请求操作
我正在尝试使用 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;
}
解决方法
您必须使用 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
})
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。