diff --git a/src/SoapCore.Tests/Wsdl/Services/ComplexComplexType.cs b/src/SoapCore.Tests/Wsdl/Services/ComplexComplexType.cs new file mode 100644 index 00000000..b59f3bd4 --- /dev/null +++ b/src/SoapCore.Tests/Wsdl/Services/ComplexComplexType.cs @@ -0,0 +1,10 @@ +using System.Xml.Serialization; + +namespace SoapCore.Tests.Wsdl.Services +{ + public class ComplexComplexType + { + [XmlElement(ElementName = "complex")] + public ComplexType ComplexType { get; set; } + } +} diff --git a/src/SoapCore.Tests/Wsdl/Services/ComplexType.cs b/src/SoapCore.Tests/Wsdl/Services/ComplexType.cs index cc6eeb7d..83bd7af0 100644 --- a/src/SoapCore.Tests/Wsdl/Services/ComplexType.cs +++ b/src/SoapCore.Tests/Wsdl/Services/ComplexType.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; using System.Xml.Serialization; namespace SoapCore.Tests.Wsdl.Services diff --git a/src/SoapCore.Tests/Wsdl/Services/IComplexComplexTypeWithCustomXmlNamesService.cs b/src/SoapCore.Tests/Wsdl/Services/IComplexComplexTypeWithCustomXmlNamesService.cs new file mode 100644 index 00000000..64e682f8 --- /dev/null +++ b/src/SoapCore.Tests/Wsdl/Services/IComplexComplexTypeWithCustomXmlNamesService.cs @@ -0,0 +1,20 @@ +using System; +using System.ServiceModel; + +namespace SoapCore.Tests.Wsdl.Services +{ + [ServiceContract] + public interface IComplexComplexTypeWithCustomXmlNamesService + { + [OperationContract] + ComplexComplexType Method(out string message); + } + + public class ComplexComplexTypeWithCustomXmlNamesService : IComplexComplexTypeWithCustomXmlNamesService + { + public ComplexComplexType Method(out string message) + { + throw new NotImplementedException(); + } + } +} diff --git a/src/SoapCore.Tests/Wsdl/Services/IComplexTypeAndOutParameterService.cs b/src/SoapCore.Tests/Wsdl/Services/IComplexTypeAndOutParameterService.cs index c6b3ba4d..abaa3bd0 100644 --- a/src/SoapCore.Tests/Wsdl/Services/IComplexTypeAndOutParameterService.cs +++ b/src/SoapCore.Tests/Wsdl/Services/IComplexTypeAndOutParameterService.cs @@ -1,7 +1,5 @@ using System; -using System.Collections.Generic; using System.ServiceModel; -using System.Text; namespace SoapCore.Tests.Wsdl.Services { diff --git a/src/SoapCore.Tests/Wsdl/WsdlTests.cs b/src/SoapCore.Tests/Wsdl/WsdlTests.cs index e4050bae..04beaca9 100644 --- a/src/SoapCore.Tests/Wsdl/WsdlTests.cs +++ b/src/SoapCore.Tests/Wsdl/WsdlTests.cs @@ -549,6 +549,50 @@ public async Task CheckComplexTypeAndOutParameterWsdl(SoapSerializer soapSeriali Assert.IsNotNull(testElementMessage); } + [DataTestMethod] + public async Task CheckComplexComplexTypeWithCustomXmlNamesWsdl() + { + var wsdl = await GetWsdlFromMetaBodyWriter(SoapSerializer.XmlSerializer); + Trace.TraceInformation(wsdl); + Assert.IsNotNull(wsdl); + + var root = XElement.Parse(wsdl); + + //loading definition of ComplexComplexType + var testComplexComplexType = GetElements(root, _xmlSchema + "complexType").SingleOrDefault(a => a.Attribute("name")?.Value == "ComplexComplexType"); + Assert.IsNotNull(testComplexComplexType); + + //checking sequence to be there + var testSequenceOfComplexComplexType = GetElements(testComplexComplexType, _xmlSchema + "sequence").SingleOrDefault(); + Assert.IsNotNull(testSequenceOfComplexComplexType); + + //checking custom name specified per XmlElementAttribute is used + var testElementOfComplexComplexType = GetElements(testSequenceOfComplexComplexType, _xmlSchema + "element").SingleOrDefault(a => a.Attribute("name").Value == "complex"); + Assert.IsNotNull(testElementOfComplexComplexType); + + //loading definition of ComplexType + var testComplexType = GetElements(root, _xmlSchema + "complexType").SingleOrDefault(a => a.Attribute("name")?.Value == "ComplexType"); + Assert.IsNotNull(testComplexType); + + //checking sequence to be there + var testSequenceOfComplexType = GetElements(testComplexType, _xmlSchema + "sequence").SingleOrDefault(); + Assert.IsNotNull(testSequenceOfComplexType); + + //checking custom names specified per XmlElementAttribute are used + var testElementWithCustomName = GetElements(testSequenceOfComplexType, _xmlSchema + "element").SingleOrDefault(a => a.Attribute("name").Value == "stringprop"); + Assert.IsNotNull(testElementWithCustomName); + + testElementWithCustomName = GetElements(testSequenceOfComplexType, _xmlSchema + "element").SingleOrDefault(a => a.Attribute("name").Value == "mybytes"); + Assert.IsNotNull(testElementWithCustomName); + + //checking both properties without custom names to use the same names as properties in the ComplexType class + var testElementWithDefaultName = GetElements(testSequenceOfComplexType, _xmlSchema + "element").SingleOrDefault(a => a.Attribute("name").Value == "IntProperty"); + Assert.IsNotNull(testElementWithDefaultName); + + testElementWithDefaultName = GetElements(testSequenceOfComplexType, _xmlSchema + "element").SingleOrDefault(a => a.Attribute("name").Value == "MyGuid"); + Assert.IsNotNull(testElementWithDefaultName); + } + [DataTestMethod] [DataRow(SoapSerializer.XmlSerializer)] public async Task CheckOccuranceOfStringType(SoapSerializer soapSerializer) diff --git a/src/SoapCore/Meta/MetaBodyWriter.cs b/src/SoapCore/Meta/MetaBodyWriter.cs index 10857c39..d042256d 100644 --- a/src/SoapCore/Meta/MetaBodyWriter.cs +++ b/src/SoapCore/Meta/MetaBodyWriter.cs @@ -921,7 +921,7 @@ private void AddSchemaTypePropertyOrField(XmlDictionaryWriter writer, MemberInfo } } - AddSchemaType(writer, toBuild, parentTypeToBuild.ChildElementName ?? elementNameFromAttribute ?? member.Name, isArray: createListWithoutProxyType, isListWithoutWrapper: createListWithoutProxyType, isUnqualified: isUnqualified, defaultValue: defaultValue); + AddSchemaType(writer, toBuild, elementNameFromAttribute ?? member.Name ?? parentTypeToBuild.ChildElementName, isArray: createListWithoutProxyType, isListWithoutWrapper: createListWithoutProxyType, isUnqualified: isUnqualified, defaultValue: defaultValue); } }