From 847ec163ce55abd693644afddd2ac6de8f6cb57a Mon Sep 17 00:00:00 2001 From: bogdan Date: Mon, 16 Jan 2017 18:08:28 +0700 Subject: [PATCH] add fields sequence if it's required --- lib/client.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/lib/client.js b/lib/client.js index 58c456f21..a61e473a1 100644 --- a/lib/client.js +++ b/lib/client.js @@ -182,6 +182,44 @@ Client.prototype._defineMethod = function(method, location) { }; }; +Client.prototype._isSequenceRequired = function(method) { + try { + if(method.input.children[0].children[0].name === 'sequence') { + return true; + } + return false; + } catch(err) { + return false; + } +}; + +Client.prototype._setSequenceArgs = function(argsScheme, args) { + var result = {}; + if(typeof argsScheme !== 'object') { + return args; + } + for (var partIndex in argsScheme) { + if(typeof args[partIndex] === 'undefined') { + continue; + } + if(typeof argsScheme[partIndex] !== 'object') { + result[partIndex] = args[partIndex]; + } + else { + result[partIndex] = this._setSequenceArgs(argsScheme[partIndex], args[partIndex]); + } + } + return result; +}; + +Client.prototype._getArgsScheme = function(methodName) { + try { + return this.wsdl.definitions.messages[methodName].parts; + } catch(err) { + return false; + } +}; + Client.prototype._invoke = function(method, args, location, callback, options, extraHeaders) { var self = this, name = method.$name, @@ -202,6 +240,13 @@ Client.prototype._invoke = function(method, args, location, callback, options, e }, xmlnsSoap = "xmlns:" + envelopeKey + "=\"http://schemas.xmlsoap.org/soap/envelope/\""; + if(this._isSequenceRequired(method)) { + var argsScheme = this._getArgsScheme(name); + if(argsScheme) { + args = this._setSequenceArgs(argsScheme, args); + } + } + if (this.wsdl.options.forceSoap12Headers) { headers["Content-Type"] = "application/soap+xml; charset=utf-8"; xmlnsSoap = "xmlns:" + envelopeKey + "=\"http://www.w3.org/2003/05/soap-envelope\"";