WCF

WCF Examples

WCF

WCF Projects

WCF Project

Data Contract Versioning
Previous Home Next

WCF needs to enable both backward and forward compatibility, without even sharing types or version information.

Types of versioning scenarios:

There are three main types of versioning scenarios.

  1. New members
  2. Missing members
  3. Round tripping, where a new version is passed to and from an old version, requiring both backward and forward compatibility
  4.  

    By default, data contracts are version tolerant and will silently ignore incompatibilities.

    1. New Members

      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;
      }
      
    2. Missing Members

      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( );
      
    3. Versioning Round-Trip:

      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.

    Previous Home Next

    Tolal:0 Click:

    Show All Comments

    Did not find what you were looking for leave your name and message. We will revert within 24 hours
    Name:
    eMail:
    Comment / Feedback: