开发者

Circular References in Web Service Objects

开发者 https://www.devze.com 2023-04-12 16:06 出处:网络
Is it possible to return an object whos refer开发者_StackOverflowences happen to be circular, as in a parent with a list of children who have access to their parent. What is the best way to facilitate

Is it possible to return an object whos refer开发者_StackOverflowences happen to be circular, as in a parent with a list of children who have access to their parent. What is the best way to facilitate this kind of thing using c# webservices.


There is no limitation of web services that prevent this, however the default serializer in .Net doesn't know how to serialize circular references. You'd need to write you're own serialization/deserialization code and plug it into WCF.

You can find a sample of doing this with WCF here: http://code.msdn.microsoft.com/WCF-Custom-Serialization-43b3ee7a


If you are using WCF, a new feature added in .net 3.5 allows you to do this with no extra code, you can serialize circular references by adding IsReference to your datacontract attribute. See http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractattribute.isreference.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号