Using IExtensibleDataObject in Clients

I converted my web service to a wcf service that has some data. As a best practice, it is mentioned and recommended that DataContracts inherit from IExtensibleDataObject. I understand that in the case of adding or deleting data, IExtensibleDataObject is useful. But I can’t get how clients will be able to access the remote data items. Here is my code:

[ServiceContract(Namespace = "http://mycompany.com/2010/08/")] public class MyWebService { [OperationContract] public Employee Add(Employee emp) { // Some Processing } } [DataContract(Name = "Employee", Namespace = "http://mycompany.com/2010/08/")] public class Employee : IExtensibleDataObject { [DataMember] public string FirstName; [DataMember] public string LastName; public ExtensionDataObject ExtensionData { get; set; } } 

Now, in my next version of the web service, I made some changes to the DataContract as

 [DataContract(Name = "Employee", Namespace = "http://mycompany.com/2010/09/")] public class Employee : IExtensibleDataObject { [DataMember] public string FirstName; [DataMember] public string LastName; [DataMember(IsRequired = true)] public string MiddleName; public ExtensionDataObject ExtensionData { get; set; } } 

However, my client, who is accessing my old version of the web service, now receives an error without supplying a MiddleName field. I'm still confused about using IExtensionDataObject.

+7
c # versioning wcf client
source share
3 answers

I'm afraid that misuse of IExtensibleDataObject, the IExtensibleDataObject interface designed to support the round-tipping version, read this MSDN article on Outlook compatibility:

http://msdn.microsoft.com/en-us/library/ms731083.aspx

And here's another article on best practices for versioning Data Contract in general: http://msdn.microsoft.com/en-us/library/ms733832.aspx

+12
source share

this is a misuse of IExtensibleDataObject. You have a modified contract with data on the server side, and you marked the new field as required, so that means that you have violated version control and nothing will help you.

IExtensibleDataObject is for other purposes. Suppose you change your client so that the data contract on the client contains MiddleName. Now you install MiddleName and use the Add service command. What is the MiddleName value in the returned Employee object? If you do not use IExtensibleDataObject, the value will be null; if you use IExtensibleDataObject, the value will be the same as you set for the parameter input.

When using the DataContractSerializer, WCF throws out all the obscure parameters. IExtensibleDataObject avoids this by storing all of these parameters in a special collection and sending them back to the client.

If you want to use the version control version, forget about the required fields. This is the first thing that will break him.

Regards, Ladislav

+12
source share

Make the ExtensionData property "Virtual" as shown below:

 public virtual ExtensionDataObject ExtensionData { get { return theData; } set { theData = value; } } 
0
source share

All Articles