Skip to content

Commit

Permalink
DataContract containing IList<struct> produces invalid WSDL DigDes#346
Browse files Browse the repository at this point in the history
  • Loading branch information
kotov.a committed Dec 10, 2019
1 parent eb5ee53 commit d2db7b8
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
36 changes: 36 additions & 0 deletions src/SoapCore.Tests/Wsdl/Services/IStructsService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace SoapCore.Tests.Wsdl.Services
{
[ServiceContract]
public interface IStructsService
{
[OperationContract]
void Method(StructService.StructModel model);
}

public class StructService : IStructsService
{
public void Method(StructModel model)
{
throw new NotImplementedException();
}

[DataContract]
public struct AnyStruct
{
public int Prop { get; set; }
}

[DataContract]
public class StructModel
{
[DataMember]
public IList<AnyStruct> MyStructs { get; set; }
}
}
}
21 changes: 21 additions & 0 deletions src/SoapCore.Tests/Wsdl/WsdlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,27 @@ public void CheckNonNullableEnum()
simpleTypeElements.ShouldNotBeEmpty();
}

[TestMethod]
public void CheckStructsInList()
{
StartService(typeof(StructService));
var wsdl = GetWsdl();
StopServer();
var root = XElement.Parse(wsdl);
var elementsWithEmptyName = GetElements(root, _xmlSchema + "element").Where(x => x.Attribute("name")?.Value == string.Empty);
elementsWithEmptyName.ShouldBeEmpty();

var elementsWithEmptyType = GetElements(root, _xmlSchema + "element").Where(x => x.Attribute("type")?.Value == "xs:");
elementsWithEmptyType.ShouldBeEmpty();

var structTypeElement = GetElements(root, _xmlSchema + "complexType").Single(x => x.Attribute("name")?.Value == "AnyStruct");
var annotationNode = structTypeElement.Descendants(_xmlSchema + "annotation").SingleOrDefault();
var isValueTypeElement = annotationNode.Descendants(_xmlSchema + "appinfo").Descendants(XNamespace.Get("http://schemas.microsoft.com/2003/10/Serialization/") + "IsValueType").SingleOrDefault();
Assert.IsNotNull(isValueTypeElement);
Assert.AreEqual("true", isValueTypeElement.Value);
Assert.IsNotNull(annotationNode);
}

[TestMethod]
public void CheckStreamDeclaration()
{
Expand Down
19 changes: 18 additions & 1 deletion src/SoapCore/Meta/MetaWCFBodyWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,18 @@ private void WriteComplexType(XmlDictionaryWriter writer, Type type)
writer.WriteAttributeString("name", toBuildName);
writer.WriteAttributeString("xmlns:ser", SERIALIZATION_NS);

if (type.IsValueType && ResolveSystemType(type).name == null)
{
writer.WriteStartElement("xs:annotation");
writer.WriteStartElement("xs:appinfo");
writer.WriteStartElement("IsValueType");
writer.WriteAttributeString("xmlns", SERIALIZATION_NS);
writer.WriteValue(true);
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndElement();
}

var hasBaseType = HasBaseType(type);

if (hasBaseType)
Expand Down Expand Up @@ -1024,11 +1036,16 @@ private void AddSchemaType(XmlDictionaryWriter writer, Type type, string name, b
xsTypename = $"{(sysType.ns == SERIALIZATION_NS ? "ser" : "xs")}:{sysType.name}";
writer.WriteAttributeString("nillable", "true");
}
else
else if (ResolveSystemType(type).name != null)
{
var sysType = ResolveSystemType(type);
xsTypename = $"{(sysType.ns == SERIALIZATION_NS ? "ser" : "xs")}:{sysType.name}";
}
else
{
var ns = $"q{_namespaceCounter++}";
xsTypename = $"{ns}:{typeName}";
}
}

writer.WriteAttributeString("minOccurs", "0");
Expand Down

0 comments on commit d2db7b8

Please sign in to comment.