views:

116

answers:

1

Is there anything I might regret later, i.e. any major limitations if we choose XmlSerialization instead of DataContract? Until now, we have embraced the schema first contract design.

For example, if we want to parameter inspection, security enhancements, etc... will locking in now with XmlSerialization be a problem when we try to add other WCF features?

+4  A: 

Certain schema elements are not supported by the DataContractSerializer, such as the xs:choice element. Know that if you end up using any of those unsupported elements, you will have a very hard time switching to Data Contracts if you ever want to.

Aside from that, there's a pretty good breakdown of the DataContractSerializer vs. XmlSerializer here. Probably the most important points are:

  • DataContractSerializer is usually more efficient;
  • DataContractSerializer can serialize fields (XmlSerializer needs properties);
  • XmlSerializer requires a public getter and setter for every serialized property (this is very annoying and can lead to some sub-optimal designs);
  • XmlSerializer requires a public parameterless constructor (DataContractSerializer will actually ignore it);
  • XmlSerializer is opt-out by default, whereas DataContractSerializer is opt-in;
  • XmlSerializer is more likely to be able to interoperate with legacy clients (i.e. ASMX web services and other platforms);

Generally speaking, the XmlSerializer gives you a lot more control over the XML, but the DataContractSerializer gives you a lot more control over the code. If you want to use the XML serializer, you sort of have to code to its whims, whereas you can integrate Data Contracts with just about any code.

Aaronaught
I was more looking into what WCF features outside of serialization might be blocked or prevented if we went with XmlSerialization. Are all other features of WCF equally applicable when we choose XmlSerialization? (And yes - we are using the "Choice" option in our XSD's. By XmlSerialization, we are just doing SOAP and not WCF really? Like for instance, can we still do SOAP-Faults with XmlSerialization?
NealWalters
@NealWalters: They added the `SupportsFaults` property in .NET 3.5 SP1, so yes, you can still do that: http://blogs.msdn.com/rickrain/archive/2008/10/03/xmlserializer-faults.aspx. The only other limitation I know about is that you can't use `XmlIncludeAttribute`, but that's replaced with `KnownTypeAttribute`. Aside from that, I think they're the same in terms of feature support, but I can't claim that I've tried anything and everything.
Aaronaught