The custom data type passed between the client and the server, in the following format:
[DataContract] Public classUser:iextensibledataobject {[DataMember] Public intID {Get;Set; } [DataMember] Public stringName {Get;Set; }
There is no [DataMember], it means that it is not passed Public stringSex {Get;Set; }
And there's no [DataMember], it's going to be passed Publicextensiondataobject ExtensionData {Get;Set; } }
For implementing interface IExtensibleDataObject, the purpose is to ensure that data is not lost. However, if a DTO is passed between the client and the server to ensure that the version is consistent, the interface may not be implemented.
The benefits of implementing IExtensibleDataObject are as follows:
The server returns the latest version of User:
Public User GetName () { returnnew User { ID=1, Name=" Apple " , Sex="M" }; }
The client version is not up-to-date and has no ID:
When the client requests:
Private Static void Main (string[] args) { new userinfoclient (); var user = client. GetName (); At this point the user is no ID, because there is no update service, resulting in version inconsistency Console.readkey (); }
At this point the extensiondata of the interface is working, it contains the ID, so that the data is not lost:
The DataContract of WCF