diff --git a/lib/wsdl.js b/lib/wsdl.js
index 7eccade33..663331308 100644
--- a/lib/wsdl.js
+++ b/lib/wsdl.js
@@ -1542,12 +1542,14 @@ WSDL.prototype.objectToXML = function(obj, name, namespace, xmlns, first, xmlnsA
if (schema) {
var childParameterTypeObject = self.findChildParameterObject(parameterTypeObject, name);
//find sub namespace if not a primitive
- if (childParameterTypeObject && childParameterTypeObject.$type && (childParameterTypeObject.$type.indexOf('xsd') === -1)) {
+ if (childParameterTypeObject &&
+ ((childParameterTypeObject.$type && (childParameterTypeObject.$type.indexOf('xsd') === -1)) ||
+ childParameterTypeObject.$ref)) {
if(childParameterTypeObject.$baseNameSpace) { //this element has a base with another namespace (the correct one)
ns = childParameterTypeObject.$baseNameSpace + ':';
}
- var childParameterType = childParameterTypeObject.$type;
+ var childParameterType = childParameterTypeObject.$type || childParameterTypeObject.$ref;
var childNamespace = '';
var childName = '';
@@ -1563,7 +1565,22 @@ WSDL.prototype.objectToXML = function(obj, name, namespace, xmlns, first, xmlnsA
ancXmlns.push(childXmlns);
}
}
- var completeChildParameterTypeObject = self.findChildParameterObjectFromSchema(childName, childXmlns) || childParameterTypeObject;
+ // There is matching element ref
+ if (childParameterTypeObject.$ref) {
+ ns = childNamespace ? childNamespace + ':' : '';
+ xmlnsAttrib = childXmlnsAttrib;
+ }
+
+ var completeChildParameterTypeObject;
+ if (childParameterTypeObject.$type) {
+ completeChildParameterTypeObject =
+ self.findChildParameterObjectFromSchema(childName, childXmlns) ||
+ childParameterTypeObject;
+ } else {
+ completeChildParameterTypeObject =
+ self.findParameterObject(childXmlns, childName) ||
+ childParameterTypeObject;
+ }
for(var ignoredNamespacesIndex = 0, ignoredNamespacesLength = this.ignoredNamespaces.length; ignoredNamespacesIndex < ignoredNamespacesLength; ignoredNamespacesIndex++) {
if(this.ignoredNamespaces[ignoredNamespacesIndex] === childNamespace) {
@@ -1671,7 +1688,8 @@ WSDL.prototype.findChildParameterObject = function(parameterTypeObj, childName)
}
var found = null,
i = 0,
- child;
+ child,
+ ref;
if(parameterTypeObj.$lookupTypes && Array.isArray(parameterTypeObj.$lookupTypes) && parameterTypeObj.$lookupTypes.length) {
var types = parameterTypeObj.$lookupTypes;
@@ -1683,12 +1701,25 @@ WSDL.prototype.findChildParameterObject = function(parameterTypeObj, childName)
found = typeObj;
break;
}
+ if(typeObj.$ref) {
+ ref = splitNSName(typeObj.$ref);
+ if (ref.name === childName) {
+ found = typeObj;
+ break;
+ }
+ }
}
} else {
var object = parameterTypeObj;
if (object.$name === childName) {
return object;
}
+ if (object.$ref) {
+ ref = splitNSName(object.$ref);
+ if (ref.name === childName) {
+ return object;
+ }
+ }
if (object.children) {
for (i = 0, child; child = object.children[i]; i++) {
diff --git a/test/wsdl-test.js b/test/wsdl-test.js
index a01c0f662..75ac17146 100644
--- a/test/wsdl-test.js
+++ b/test/wsdl-test.js
@@ -73,6 +73,22 @@ wsdlStrictTests['should get the parent namespace when parent namespace is empty
});
};
+wsdlStrictTests['should handle element ref'] = function(done) {
+ var expectedMsg = '' +
+ '' +
+ '001' +
+ '';
+ soap.createClient(__dirname + '/wsdl/elementref/foo.wsdl', {strict: true}, function(err, client) {
+ assert.ok(!err);
+ client.fooOp({paymentRq: {bankSvcRq: {requestUID: '001'}}}, function(err, result) {
+ assert.equal(client.lastMessage, expectedMsg);
+ done();
+ });
+ });
+};
+
module.exports = {
'WSDL Parser (strict)': wsdlStrictTests,
'WSDL Parser (non-strict)': wsdlNonStrictTests
diff --git a/test/wsdl/elementref/bar.xsd b/test/wsdl/elementref/bar.xsd
new file mode 100644
index 000000000..051f1e1a3
--- /dev/null
+++ b/test/wsdl/elementref/bar.xsd
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/wsdl/elementref/bar1.xsd b/test/wsdl/elementref/bar1.xsd
new file mode 100644
index 000000000..a8432d487
--- /dev/null
+++ b/test/wsdl/elementref/bar1.xsd
@@ -0,0 +1,40 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/wsdl/elementref/foo.wsdl b/test/wsdl/elementref/foo.wsdl
new file mode 100755
index 000000000..0f81b1913
--- /dev/null
+++ b/test/wsdl/elementref/foo.wsdl
@@ -0,0 +1,53 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+