问题描述
我正在尝试使用 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
})