I have the following code
namespace A
{
[DataContract]
public class CustomClass {}
}
how could I decorate the DataContract attribute, or what I must change on server side to change the code into
namespace B
{
[DataContract(...)]
public class CustomClass {}
}
and all existing clients to connect without problems to this client.
Note: I can’t change any client, only on server side.
That depends on what binding (and more specifically, which serializer) you are using. If you are using
DataContractSerializer, then the answer is simple: do nothing. Those two contracts are equivalent; the wire data is defined by:[DataContract(...)], if one – else the class name (which matches)[DataContract(...)]If you are using
NetDataContractSerializer, simple: you can’t.Note that the c# namespace used at the client is entirely up to the client, and is typically determined by the tooling used to generate the type. Frankly, it doesn’t matter what the client uses as the c# namespace, as long as they are using a contract-based serializer such as
XmlSerializerorDataContractSerializer.To illustrate this: this prints the same thing twice: