WCF

R4R® WCF with C# WCF Tutorials
(追記) (追記ここまで)
(追記) (追記ここまで)
Data Contract Versioning

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.

    (追記) (追記ここまで)
Hot Topics

Database & SQL

HR FAQs

Interview & FAQs

ASK Questions

PHP

Testing

More Links

Tutorials

Articles

Source Code

e-Books

Certifications

FAQS

Copyright ©2021-22 r4r.co.in, all rights reserved. Theguestspost.com
Sitemap
Career
Post comment
About us
Subscription
Unsubscription

AltStyle によって変換されたページ (->オリジナル) /