Versioning round trip in WCF
-
Sunday, March 11, 2012 8:12 AM
Hi,
As far as my knowledge is concerned about Versioning round trip in WCF, its about preserving unknown/additional data members. This can be achieved on implementing IExtensibleDataObject<m:smallfrac m:val="off"><m:dispdef><m:lmargin m:val="0"><m:rmargin m:val="0"><m:defjc m:val="centerGroup"></m:defjc></m:rmargin></m:lmargin></m:dispdef></m:smallfrac> interface in Data Contracts. I have defined a Data Contract as following:
[DataContract]
public class EmpInfo:IExtensibleDataObject
{
[DataMember]
public int EmpID;
[DataMember]
public string EmpName;
#region IExtensibleDataObject Members
private ExtensionDataObject extensionData;
public ExtensionDataObject ExtensionData
{
get { return extensionData; }
set { extensionData = value; }
}
#endregion
}
My service implementation is as following:
public EmpInfo GetEmployeeData(EmpInfo info)
{
return new EmpInfo { EmpID = info.EmpID, EmpName = info.EmpName};
}I am consuming the service fro client using the following code: I am sending one additional Data Member "EmpAddress" in the EmpInfo class and receiving the response from the service.
static void Main(string[] args)
{
using (MyServiceClient proxy = new MyServiceClient())
{
var sc = proxy.GetEmployeeData(new EmpInfo { EmpID = 1, EmpName = "AA", EmpAddress="MM"});
Console.WriteLine("Employee ID: " + sc.EmpID);
Console.WriteLine("Employee Name: " + sc.EmpName);
Console.WriteLine("Employee Address: " + sc.EmpAddress);
}
Console.ReadLine();
}As I have implemented my Data Contract from IExtensibleDataObject interface, I am expecting that the additional/unknown value sent by client(i.e EmpAddress) would not be lost and returned in round trip. But while, I am printing the value of "EmpAddress" in console, it is displayed as blank. What could be reason of this behaviour? Where I am doing the mistake?
Thanks in advance.
Regards
ronit_rc
All Replies
-
Sunday, March 11, 2012 8:48 AM
Hi,
I think your problem is here:
public EmpInfo GetEmployeeData(EmpInfo info)
{
return new EmpInfo { EmpID = info.EmpID, EmpName = info.EmpName};
}You are returning a New EmpInfo object and not the object that was sent in the first place.
Try this:
public EmpInfo GetEmployeeData(EmpInfo info)
{
return new EmpInfo { EmpID = info.EmpID, EmpName = info.EmpName, ExtensionData = info.ExtensionData};
}- Proposed As Answer by Dragan Radovac Monday, March 12, 2012 8:55 AM
- Marked As Answer by Steven Cheng - MSFTMicrosoft Employee, Moderator Thursday, March 15, 2012 10:45 AM
-
Thursday, March 15, 2012 4:43 AM
Hi,
Thanks a lot for your answer. It worked.
Regards
ronit_rc
- Marked As Answer by ronit_rc Thursday, March 15, 2012 4:44 AM

