Version of WCF data contract

Source: Internet
Author: User

WCF data contractVersion

Lazybee

1 Disruptive change

After modifying the data contract (new version) of a certain party (Service and client) based on the existing data contract (old version, the communication between the service and the client is not normal (one-way or two-way). We call this change an interruption change, otherwise it is a non-interruption change. For example, the following changes are all disruptive changes:

1.1Modify the name or namespace of a Data contract

1.2Change the sequence of Data contract members

1.3Modify the name of a Data contract Member

1.4Modify the data contract member type

1.5Add or delete an enumerated member and modify the name of the enumerated member (EnummemberattributeTo make it consistent with the old version)

2 Non-disruptive changes

Any changes to the types that do not affect data transmission and receipt are non-disruptive changes. In most cases, adding or deleting a data contract member is a non-disruptive change.

2.1 Add new data contract members

The most common change is to add a new data contract member to one party, and then send the new contract to the service or client of the old contract. When deserializing this type,DatacontractserializerThe newly added members will be ignored. If new members are required, this change will be an interrupted change because there is no problem with the new version to the old version, however, in the opposite direction (see the case of missing members), the communication will fail; otherwise, this change will be a non-disruptive change.

2.2 Version round-trip

This is a special case for new data contract members.,The data transmission path is from the new data contract to the old data contract, and then back to the new data contract. For example:

Client ----ÀService -------ÀService B (ClientAndService BAll use the new data contract, andServiceThe old data contract is used, which is a common case of calling the service chain.)

Client ---ÀService ------ÀClient (ClientThe new data contract is used,ServiceThe old data contract is used. This is when the same data contract is used for the input and output parameters or return values of service operations.)

Follow2.1From the new version to the old version,DatacontractserializerThe new data is ignored.Service BAndClientNo new data contract members will be received. Is there a way for them to receive data that contains new data contract members? The answer is yes.WCFProvidedIextensibledataobjectTo achieve this goal, add data toExtensiondataobjectTo ensure that the new data is available in other subsequent transmission processes:

 
Public interface iextensibledataobject
 
{
 
Extensiondataobject extensiondata
{Get; set ;}
 
}
 
Of course, even if the data contract type implements the iextensibledataobject interface, you can use the ignoreextensiondataobject attribute of servicebehaviorattribute to force datacontractserializer to ignore new members.
2.3 Missing data member

If the change to the old data contract is to delete the data contract member, the following situations exist:

ØMissing data members are not required in the Data contract

This data member (Datamemberattriubte)IsrequiredThe property value is not set orFalse.For this missing data member, the default value will be used during deserialization.0OrNull. You can also useOndeserializingattributeOrOndeserizlizedattributeTo set the default value you want. This is a non-disruptive change.

ØMissing data members are required in the Data contract

If the missing data member is required in the Data contract, an exception is thrown during deserialization. This is an interrupted change.

2.4 Others

if you set datamemberattribute emitdefadefavalue set the attribute to false ( default value: true), if this value is the default value during serialization, the data member will not be serialized and the missing data member will be formed at the other end, that is to say, if this member is required, an exception will be thrown during deserialization.

IfDatamemberattributeOfEmitdefavalue ValueSet propertyFalse (The default value isTrue)The default value is unacceptable during deserialization. If the Member is required, an exception is thrown.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.