4

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) ?

Luk
  • 5,371
  • 4
  • 40
  • 55
  • Are all the Types being used by `DocumentTreeNode` ISerializable ? They all need to be, preferably using the ISerializable Attribute. See: http://stackoverflow.com/questions/2365152/whats-the-difference-between-using-the-serializable-attribute-implementing-ise – cofiem Aug 26 '10 at 13:16
  • Yes, the DocumentTreeNode is marked as [Serializable], and all its properties are serializable too – Luk Aug 26 '10 at 13:20
  • Josh: No, it's a plain ASP.Net 2.0 webservice – Luk Aug 26 '10 at 13:22
  • 1
    Any luck if you change the return type out for an `IList`? – kbrimington Aug 26 '10 at 13:26
  • kbrimington> It looks like you are right. Using a plain old List makes the serialization work. Damn... – Luk Aug 26 '10 at 13:50

1 Answers1

1

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
  • 142,167
  • 33
  • 283
  • 313
  • Thanks a lot! For the record, I ended replacing it with a plain List (apparently LinkedList is not easily serializable either) – Luk Aug 27 '10 at 20:21