views:

36

answers:

1

Hello,

I have a webservice 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 the webservice, 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 have double checked, and the object I am supposed to return is not empty.

I'm guessing that means ASP.Net is unable to properly serialize my class (due to the IEnumerable?). I was going to use an Xml Serialization and have my service return an XmlDocument, but I don't think this is the best way.

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

+1  A: 

Properties that return interfaces are skipped by the serializer. It requires a concrete type, otherwise re-hydration would be impossible without additional type metadata sent along, which is not part of the OOTB serialization.

Rex M
Thanks a lot! For the record, I ended replacing it with a plain List<DocumentTreeNode> (apparently LinkedList is not easily serializable either)
Luk