我试图通过回送项目中的SOAP服务将JSON转换为XML。
我使用了strong-soap npm
库。
但是我找不到将JSON转换为XML的解决方案。
我尝试过。
var soap = require('strong-soap').soap;
var XMLHandler = soap.XMLHandler;
var xmlHandler = new XMLHandler();
var util = require('util');
var url = 'http://www.webservicex.net/stockquote.asmx?WSDL';
var requestArgs = {
symbol: 'IBM'
};
var options = {};
var clientOptions = {};
soap.createClient(url, clientOptions, function(err:any, client:any) {
var customRequestHeader = {customheader1: 'test1'};
client.GetQuote(requestArgs, function(err:any, result:any, envelope:any, soapHeader:any) {
// Convert 'result' JSON object to XML
var node = xmlHandler.jsonToXml(null, null,
XMLHandler.createSOAPEnvelopeDescriptor('soap'), result);
var xml = node.end({pretty: true});
console.log(xml);
// Convert XML to JSON object
var root = xmlHandler.xmlToJson(null, xml, null);
console.log('%s', util.inspect(root, {depth: null}));
}, options, customRequestHeader);
});
错误。
TypeError: Cannot read property 'GetQuote' of undefined
at /.../dist/controllers/payments.controller.js:165:20
at /.../node_modules/strong-soap/src/soap.js:54:5
at /home/milutin/Sources/boom-platform-api/api/node_modules/strong-soap/src/soap.js:36:16
at /.../node_modules/strong-soap/src/parser/wsdl.js:487:13
at Request._callback (/.../node_modules/strong-soap/src/http.js:169:9)
at Request.self.callback (/.../node_modules/request/request.js:185:22)
at Request.emit (events.js:198:13)
at Request.<anonymous> (/.../node_modules/request/request.js:1161:10)
at Request.emit (events.js:198:13)
at IncomingMessage.<anonymous> (/.../node_modules/request/request.js:1083:12)
at Object.onceWrapper (events.js:286:20)
at IncomingMessage.emit (events.js:203:15)
at endReadableNT (_stream_readable.js:1129:12)
at process._tickCallback (internal/process/next_tick.js:63:19)
如何解决此错误? 谢谢。