You should look at DataContractSerializer ; it uses the opt-in approach for serialization.
It would also be nice to read XmlSerializer vs DataContractSerializer: Serialization in Wcf for examples and comparisons between DataContractSerializer and XmlSerializer .
XmlSerializer has been in .Net since version 1.0 and serves us well for everything from Remoting, Web Services, serialization to file, etc. However, in .Net 3.0 came DataContractSerializer. And all of a sudden, a lot of guidance suggests that we should use its old proven XmlSerializer. Wcf even uses this as the default serialization mechanism. Question: "Is it really better?" The verdict is yes and no. Like most, it all depends on your implementation and what you need. For Wcf, you should prefer to use the DataContractSerializer. If you need full control over what xml looks like though, you should go back to XmlSerializer.
source share