在 Node.js 中调用 SOAP 请求操作
Call SOAP request operation in Node.js
我正在尝试使用 node-soap 发出 SOAP 请求 - 我可以成功创建客户端,但是当我尝试调用 WSDL 中定义的操作时,它 returns 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) - call method on the SOAP service.
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
})
我正在尝试使用 node-soap 发出 SOAP 请求 - 我可以成功创建客户端,但是当我尝试调用 WSDL 中定义的操作时,它 returns 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) - call method on the SOAP service.
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 })