I created a SOAP server in Node.js
const soap = require('soap');
const http = require('http');
const XMLWriter = require('xml-writer');
const service = {
ImpDispatcherService: {
ImpDispatcher: {
performTest: function (args) {
const xw = new XMLWriter(true);
xw.startDocument();
xw.startElement('result');
queryDatabase(args.parameter1, xw).then(success => {
console.log(success);
xw.endDocument();
console.log(xw.toString()); // -> prints the full XML-File
});
return { testResult: xw.toString() };
}
}
}
};
var server = http.createServer((request, response) => {
response.end('404: Not Found: ' + request.url);
});
// Create the SOAP server
const xml = require('fs').readFileSync(`${__dirname}/ImpDispatcherService.wsdl`, 'utf8');
var server = http.createServer((request, response) => {
response.end('404: Not Found: ' + request.url);
});
server.listen(8000, 'localhost');
soap.listen(server, '/imp', service, xml, () => {
logger.info('Server initialized');
});
async function queryDatabase(pars) {
const oracledb = require('oracledb');
const connection = await oracledb.getConnection(db);
const result = await connection.execute(`BEGIN :ret := getResult(${pars}); END;`, {ret: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR } });
let row;
while (row = await result.outBinds.ret.getRow()) {
xw.writeElement('tag', row.blabla);
}
return true;
}
When I make a SOAP request from client, then it returns only empty <result/>
element but not the elements I added inside queryDatabase().
2
Answers
I found a solution:
However, I did not manage it to define the function inside the
service
object. But this is mainly cosmetic.You don’t have a return statement in performTest, so it’s implicitly returning undefined, instead of a promise. Also,
.then(result => result)
has no effect. The promise created by queryDatabase will already resolve toresult
.Try this instead: