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?
More info
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.
Other attempt:
We also tried to do it by using different Namespaces for each ContractDescription instance. That way we would keep the same contract interface (IIncidentService) but with two different namespaces:
http://ourcompany/XML/IIncidentService
http://ourcompany/DCS/IIncidentService
With that we were able to get farther but the service crashed with a weird exception:
An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:
System.InvalidOperationException: An exception was thrown in a call to a WSDL export extension: System.ServiceModel.Description.XmlSerializerOperationBehavior
contract: http://ourcompany.cs/XML:IUserServiceWCF ----> System.NullReferenceException: Object reference not set to an instance of an object.
at System.ServiceModel.Description.XmlSerializerMessageContractExporter.ExportFaults(Object state)
at System.ServiceModel.Description.MessageContractExporter.ExportMessageContract()
at System.ServiceModel.Description.XmlSerializerOperationBehavior.System.ServiceModel.Description.IWsdlExportExtension.ExportContract(WsdlExporter exporter, WsdlContractConversionContext contractContext)
at System.ServiceModel.Description.WsdlExporter.CallExtension(WsdlContractConversionContext contractContext, IWsdlExportExtension extension)