locked
Versioning round trip in WCF RRS feed

  • Question

  • 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

    Sunday, March 11, 2012 8:12 AM

Answers

  • 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};
      }

    Sunday, March 11, 2012 8:48 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
    Thursday, March 15, 2012 4:43 AM

All replies

  • 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
    Thursday, March 15, 2012 4:43 AM