I want to pass a fairly generic set of data through a WCF method. The data is basically just a hierarchical set of key/value pairs, but it's nested to an arbitrary level. I originally considered passing it though as a single string and doing XML or JSON or similar encoding/decoding at either end, but since the WCF transport is XML anyway that seemed a little silly, so I'm hoping there's a way to pass it through "naturally".
The method is fairly straightforward:
[OperationContract]
void ProcessData(DataTree tree);
with:
public class DataTree : Dictionary<string, DataTree>
{
}
This all compiles fine, but when I try to run the service it crashes with a StackOverflowException under DataContract.GetStableName.
I've tried putting a [CollectionDataContract]
attribute on the DataTree
class and explicitly specifying all the names, but that didn't seem to make any difference.
I've also tried putting a [DataContract]
on it, but then it fails even earlier because Dictionary
is ISerializable
.
Any ideas? Is there a better way to do this?