递归对象未通过 WCF 传递 [英] Recursive object not passed over WCF

查看:21
本文介绍了递归对象未通过 WCF 传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我会解释我的班级设计

public class A
{
   public Ilist<B> Something { get; set; }
}

public class B
{
   public A ParentA { get; set; }
}

现在我试图通过 WCF 传递 A 并且它只是抛出异常.是否必须设置一些属性才能使其正常工作,或者在 WCF 中根本不可能

Now I am trying to pass A over WCF and it just throws an exception. Is there some attribute I have to set to get this to work or is it not at all possible in WCF

推荐答案

尝试装饰类 A:

[DataContract(IsReference = true)]

只有 B 类:

[DataContract]

这将告诉 WCF 这些是您将在您的服务中使用的类型,并且 IsReference 将处理循环引用问题并减少您的消息大小.您也可以尝试将 IsReference 放在 B 上而不是 A 上 - 我不记得它在我头顶上的确切表现.

That will tell WCF that these are types you're going to be using in your service, and IsReference will take care of the circular reference problem as well as cutting down on the size of your message. You might also try playing around with putting IsReference on B and not on A - I don't recall exactly how it behaves off the top of my head.

这篇关于递归对象未通过 WCF 传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆