IsReference property in data contract

It determines how objects are serialized, by default, IsReference=false. Setting IsReference = true allows the serialization of trees of objects that can reference each other. So with a list of Employees that each have a property for Manager (who is also an Employee), a reference to the Manager for each Employee can be held rather … Read more

How to use Custom Serialization or Deserialization in WCF to force a new instance on every property of a datacontact ?

If your are using DataContract serialization then you can override its default behaviour using the OnDeserialized attribute. From MSDN: When applied to a method, specifies that the method is called during deserialization of an object in an object graph. The order of deserialization relative to other objects in the graph is non-deterministic. Here is my … Read more

Namespace for [DataContract]

DataContractAttribute Class is in the System.Runtime.Serialization namespace. You should add a reference to System.Runtime.Serialization.dll. That assembly isn’t referenced by default though. To add the reference to your project you have to go to References -> Add Reference in the Solution Explorer and add an assembly reference manually.

How can you control .NET DataContract serialization so it uses XML attributes instead of elements?

You can do this with the DataContractSerializer – the answer is to take over the Xml serialization yourself by implementing the IXmlSerializable interface. For write-only support – you can leave the implementation of ReadXml empty, and return null for GetSchema, and then write the implementation of WriteXml as follows: public class MyPerson : IXmlSerializable { … Read more