How to return an interface or a "complex" value using webservice?

I have a web service that returns a complex value (this is a tree)

public class DocumentTreeNode { public MyDocument Data { get; set;} private LinkedList<DocumentTreeNode> _children; public IEnumerable<DocumentTreeNode> Children { get { return _children.AsEnumerable(); } } (...) } 

Unfortunately, when I call a web service, it returns

 <?xml version="1.0" encoding="utf-8"?> <DocumentTreeNode xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/" /> 

I checked double and the object I have to return is not empty.

I assume ASP.Net cannot properly serialize my class (due to IEnumerable?). I was going to use Xml Serialization and my service returns an XmlDocument, but I don't think this is the best way.

What is the easiest way to pass this object (with minimal work)?

+4
source share
1 answer

Properties that return interfaces are skipped by the serializer. It requires a specific type, otherwise rehydration is not possible without sending another type of metadata, which is not part of OOTB serialization.

+1
source

All Articles