diff --git a/package.json b/package.json
index ff8b36f3f..73aa5a5f9 100644
--- a/package.json
+++ b/package.json
@@ -36,7 +36,7 @@
"cover": "nyc --reporter=lcov --reporter=html --reporter=text mocha --exit test/*-test.js test/security/*.js",
"coveralls": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js -v",
"docs": "typedoc --out docs",
- "test": "mocha --timeout 10000 --bail --exit test/*-test.js test/security/*.js"
+ "test": "mocha --timeout 15000 --bail --exit test/*-test.js test/security/*.js"
},
"keywords": [
"soap"
diff --git a/src/wsdl/index.ts b/src/wsdl/index.ts
index 8faf34389..ffb9fb5e3 100644
--- a/src/wsdl/index.ts
+++ b/src/wsdl/index.ts
@@ -689,10 +689,14 @@ export class WSDL {
// start building out XML string.
if (Array.isArray(obj)) {
var nonSubNameSpace = '';
+ var emptyNonSubNameSpaceForArray = false;
var nameWithNsRegex = /^([^:]+):([^:]+)$/.exec(name);
if (nameWithNsRegex) {
nonSubNameSpace = nameWithNsRegex[1];
name = nameWithNsRegex[2];
+ } else if (name[0] === ':') {
+ emptyNonSubNameSpaceForArray = true;
+ name = name.substr(1);
}
for (i = 0, n = obj.length; i < n; i++) {
@@ -702,7 +706,10 @@ export class WSDL {
var body = self.objectToXML(item, name, nsPrefix, nsURI, false, null, schemaObject, nsContext);
- var openingTagParts = ['<', appendColon(correctOuterNsPrefix), name, arrayAttr, xmlnsAttrib];
+ var openingTagParts = ['<', name, arrayAttr, xmlnsAttrib];
+ if (!emptyNonSubNameSpaceForArray) {
+ openingTagParts = ['<', appendColon(correctOuterNsPrefix), name, arrayAttr, xmlnsAttrib];
+ }
if (body === '' && self.options.useEmptyTag) {
// Use empty (self-closing) tags if no contents
@@ -715,7 +722,11 @@ export class WSDL {
}
parts.push(body);
if (self.options.namespaceArrayElements || i === n - 1) {
- parts.push(['', appendColon(correctOuterNsPrefix), name, '>'].join(''));
+ if (emptyNonSubNameSpaceForArray) {
+ parts.push(['', name, '>'].join(''));
+ } else {
+ parts.push(['', appendColon(correctOuterNsPrefix), name, '>'].join(''));
+ }
}
}
}
@@ -874,7 +885,11 @@ export class WSDL {
obj[self.options.attributesKey].xsi_type.xmlns, false, null, null, nsContext);
} else {
if (Array.isArray(child)) {
- name = nonSubNameSpace + name;
+ if(emptyNonSubNameSpace) {
+ name = ':' + name;
+ } else {
+ name = nonSubNameSpace + name;
+ }
}
value = self.objectToXML(child, name, nsPrefix, nsURI, false, null, null, nsContext);
diff --git a/test/client-test.js b/test/client-test.js
index 2d5a22575..609e99e0d 100644
--- a/test/client-test.js
+++ b/test/client-test.js
@@ -94,12 +94,12 @@ var fs = require('fs'),
});
});
-
+
it('should allow passing in XML strings', function (done) {
soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', _.assign({ envelopeKey: 'soapenv' }, meta.options), function (err, client) {
assert.ok(client);
assert.ifError(err);
-
+
var xmlStr = '\n\t
\n\t\t404 - Not Found\n\t\n\t\n\t\t404 - Not Found
\n\t\t\n\t\n';
client.MyOperation({_xml: xmlStr}, function (err, result, raw, soapHeader) {
assert.ok(err);
@@ -210,7 +210,7 @@ var fs = require('fs'),
}, 'https://127.0.0.1:443');
});
-
+
it('should have xml request modified', function (done) {
soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', meta.options, function(err, client) {
assert.ok(client);
@@ -230,7 +230,7 @@ var fs = require('fs'),
);
}, baseUrl);
});
-
+
it('should have the correct extra header in the request', function (done) {
soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', meta.options, function (err, client) {
assert.ok(client);
@@ -905,6 +905,52 @@ var fs = require('fs'),
});
});
+ it('shall generate correct payload for methods with array parameter with colon override', function (done) {
+ soap.createClient(__dirname + '/wsdl/array_namespace_override.wsdl', function(err, client) {
+ assert.ok(client);
+ var pathToArrayContainer = 'SampleArrayServiceImplService.SampleArrayServiceImplPort.createWebOrder.input.order';
+ var arrayParameter = _.get(client.describe(), pathToArrayContainer)['orderDetails[]'];
+ assert.ok(arrayParameter);
+ const input = {
+ ':clientId': 'test',
+ ':order': {
+ ':orderDetails': {
+ ':unitNo': 1234,
+ ':items':[{ ':itemDesc': 'item1'}, { ':itemDesc': 'item2'}]
+ },
+ },
+ };
+ client.createWebOrder(input, function() {
+ var sentInputContent = client.lastRequest.substring(client.lastRequest.indexOf(''), client.lastRequest.lastIndexOf('') + ''.length);
+ assert.equal(sentInputContent, 'item1item2');
+ done();
+ });
+ });
+ });
+
+ it('shall generate correct payload for methods with array parameter with parent namespace', function (done) {
+ soap.createClient(__dirname + '/wsdl/array_namespace_override.wsdl', function(err, client) {
+ assert.ok(client);
+ var pathToArrayContainer = 'SampleArrayServiceImplService.SampleArrayServiceImplPort.createWebOrder.input.order';
+ var arrayParameter = _.get(client.describe(), pathToArrayContainer)['orderDetails[]'];
+ assert.ok(arrayParameter);
+ const input = {
+ ':clientId': 'test',
+ ':order': {
+ 'orderDetails': {
+ ':unitNo': 1234,
+ 'items':[{ ':itemDesc': 'item1'}, { ':itemDesc': 'item2'}]
+ },
+ },
+ };
+ client.createWebOrder(input, function() {
+ var sentInputContent = client.lastRequest.substring(client.lastRequest.indexOf(''), client.lastRequest.lastIndexOf('') + ''.length);
+ assert.equal(sentInputContent, 'item1item2');
+ done();
+ });
+ });
+ });
+
it('shall generate correct payload for methods with array parameter when individual array elements are not namespaced', function (done) {
// used for servers that cannot aggregate individually namespaced array elements
soap.createClient(__dirname + '/wsdl/list_parameter.wsdl', {disableCache: true, namespaceArrayElements: false}, function(err, client) {
@@ -1001,7 +1047,7 @@ var fs = require('fs'),
});
});
-
+
describe('Client created with createClientAsync', function () {
it('should error on invalid host', function (done) {
soap.createClientAsync('http://localhost:1', meta.options)
@@ -1057,7 +1103,7 @@ var fs = require('fs'),
done();
});
});
-
+
it('should allow customization of request for http client', function (done) {
var myRequest = function () {
};
diff --git a/test/wsdl/array_namespace_override.wsdl b/test/wsdl/array_namespace_override.wsdl
new file mode 100644
index 000000000..c986a9baa
--- /dev/null
+++ b/test/wsdl/array_namespace_override.wsdl
@@ -0,0 +1,98 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+