WCF needs to enable both backward and forward compatibility, without even sharing types or version information.
There are three main types of versioning scenarios.
By default, data contracts are version tolerant and will silently ignore incompatibilities.
Both the service and the client can accept data with new members that were not part of original contract when the new members can simply be ignored by DataContractSerializer when deserializing the type.
For example, the service may be built against this data contract:
[DataContract]
struct Contact
{
[DataMember]
public string FirstName;
[DataMember]
public string LastName;
}
and yet the client may send it this data contract instead:
[DataContract]
struct Contact
{
[DataMember]
public string FirstName;
[DataMember]
public string LastName;
[DataMember]
public string Address;
}
Missing members are initialized to their default value
////////////////////// Service Side ////////////////////////
[DataContract]
struct Contact
{
[DataMember]
public string FName;
[DataMember]
public string LName;
[DataMember]
public string Address;
}
[ServiceContract]
interface IContactManager
{
[OperationContract]
void AddContact(Contact contact);
...
}
class ContactManager : IContactManager
{
public void AddContact(Contact contact)
{
Trace.WriteLine("First name = " + contact.FirstName);
Trace.WriteLine("Last name = " + contact.LastName);
Trace.WriteLine("Address = " + (contact.Address ?? "Missing"));
...
}
...
}
///////////////////// Client Side ///////////////////////
[DataContract]
struct Contact
{
[DataMember]
public string FirstName;
[DataMember]
public string LastName;
}
Contact contact = new Contact( );
contact.FirstName = "Kamal";
contact.LastName = "Ashish";
ContactManagerClient proxy = new ContactManagerClient( );
proxy.AddContact(contact);
proxy.Close( );
The versioning tolerance techniques described so far for ignoring new members and defaulting missing ones are suboptimal. The versioning tolerance techniques enable a point-to-point client-to-service call but have no support for a wider-scope pass-through scenario.
Others
Languages
Frameworks
Web / Design
Mobile Technology
Sql & Technology
R4R