从WCF服务返回递归结构
我有下面的数据结构来表示树从WCF服务返回递归结构,wcf,recursion,Wcf,Recursion,我有下面的数据结构来表示树 public class TreeNode : IEnumerable<TreeNode> { private readonly Dictionary<string, TreeNode> _children = new Dictionary<string, TreeNode>(); public readonly string ID;
public class TreeNode : IEnumerable<TreeNode>
{
private readonly Dictionary<string, TreeNode> _children =
new Dictionary<string, TreeNode>();
public readonly string ID;
public TreeNode Parent { get; private set; }
public TreeNode()
{
this.ID = Guid.NewGuid().ToString();
}
public void AddChild(TreeNode tNode)
{
if (tNode.Parent != null)
{
tNode.Parent._children.Remove(tNode.ID);
}
tNode.Parent = this;
this._children.Add(tNode.ID, tNode);
}
public IEnumerator<TreeNode> GetEnumerator()
{
return this._children.Values.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}
}
和我得到的例外是“Type”TeeNoDE是一个不被支持的递归集合数据契约。考虑修改集合“树”的定义来删除对自身的引用。 当我用
[DataContract(IsReference=true)]
注释TreeNode Cals时,异常消失了。
但是,当在客户端接收到treenode时,它的children\u children
属性不会被填充,并且它始终为null
谢谢,
Mallikarjun用
数据成员注释\u子项
,问题得到解决
[OperationContract]
TreeNode GetMenuItems();