Is it possible to replace dataContractSerializer in Windows Communication Foundation with my own serializer. If it is possible, how can I achieve this?
Is it possible to replace dataContractSerializer in Windows Communication Foundation with my own serializer.
Share
Yes, you can provide your own serializer implementation. By default WCF will use the
DataContractSerializer. To provide your own serializer you must write your ownIOperationBehaviorwhich seeks out and removes the currently appliedDataContractSerializerOperationBehaviorfrom theOperationDescription::Behaviorscollection and then applies a custom instance of anDataContractSerializerOperationBehavior. The DataContractSerializerOperationBehavior is then responsible for constructing anXmlObjectSerializerimplementation in it’sCreateSerializerfactory methods. For some code samples for how to do this, check out this article by Dan Rigsby.From there, it’s all about implementing your own custom
XmlObjectSerializerwhich will allow you to serialize the XML infoset to any representation you want.