Circular References in Web Service Objects
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
精彩评论