How to support both DataContractSerializer and XMLSerializer for the same contract on the same host?

Posted by Sly on Stack Overflow See other posts from Stack Overflow or by Sly
Published on 2010-06-11T19:50:30Z Indexed on 2010/06/11 19:52 UTC
Read the original article Hit count: 250

In our production environment, our WCF services are serialized with the XMLSerializer. To do so our service interfaces have the [XMLSerializerFormat] attribute. Now, we need to change to DataContractSerializer but we must stay compatible with our existing clients. Therefore, we have to expose each service with both serializers.

We have one constraint: we don't want to redefine each contract interface twice, we have 50 services contract interfaces and we don't want to have

IIncidentServiceXml 
IIncidentServiceDCS
IEmployeeServiceXml 
IEmployeeServiceDCS
IContractServiceXml 
IContractServiceDCS

How can we do that?


This is a description of what we have tried so far but I'm willing to try completely different approaches:

We tried to create all the endpoints by code in our own ServiceHostFactory class. Basically we create each endpoint twice. The problem is that at runtime, WCF complains that the service has two endpoints with the same contact name but with different ContractDescription instances. The message says we should use different contract names or reuse the same ContractDescription instance.

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET