none
Custom Operations in the setter is not exposed properly in the client side RRS feed

  • Question

  • Hi,

    Greetings for the day.

    I am exposing the properties to the client through WCF.

    In the setter method i am haing some custom operation which will do something on the incoming value.

    Ex:
    Case (1) My original code:-

        [DataContract]
        public class CompositeClass : INotifyPropertyChanged
        {
            private string _myData;
            [DataMember]
            public string MyData
            {
                get
                {
                    return _myData;
                }

                set
                {
                    _myData = getThisData();             ****Do something on the incoming value****
                    if (PropertyChanged != null)
                    {
                        PropertyChanged(this, new PropertyChangedEventArgs("MyData"));
                    }                
                }
            }


            public string getThisData()
            {
                string a = "Custom method executed";
                return a;
            }

            public event PropertyChangedEventHandler PropertyChanged;
        }



    But when i exposed the service to the client , i can able to see the difference of those exposed properties.

    Ex:

    Case (2) The reference produced, on consuming the wcf service:-

      [System.Runtime.Serialization.DataMemberAttribute()]
            public string MyData {
                get {
                    return this.MyDataField;
                }
                set {
                    if ((object.ReferenceEquals(this.MyDataField, value) != true)) 
    {
                        this.MyDataField = value;                    ****Here no changes got reflected****
                        this.RaisePropertyChanged("MyData");
                    }
                }
            }



    Even i did like,

    _myData = "ConstantData";                         ****Instead of calling another function****
                    if (PropertyChanged != null)
                    {
                        PropertyChanged(this, new PropertyChangedEventArgs("MyData"));
                    }


    But for that too; case (2) is same to same.

    Case (3):

    But i can able to alter the reference file of the service (reference.Cs). 

    But it is not worthy since , when i update the service reference, it will generate its own proxy class again.

    My Question:-

    Whether the above mentioned case (2) will be the default template for all the properties? 

    Is there any way to exactly have what i did in the case (1).


    May i kindly know,  where i went wrong and how to correct it and is there any way to achive of what i am thiniking.


    Thanks in advance.

            

    NANDAKUMAR.T


    Monday, February 16, 2015 6:52 AM

Answers

  • No code that you put in your getters and setters will ever be serialized when you add a service reference. That is not how services work. When you add the service reference, a class is created in the client project based on the attributes that you have decorated your data contract with in the service project. Each property decorated with the [DataMember] attribute gets added to the client class but no other code or behaviour is added to the automatically generated class.

    If you want to use the very same DataContract class definitions on both the service and the client side, you should put these classes in a seperate assembly (project) and then add a reference to this assembly from both the service and the client projects.

    Please remember to close your threads by marking helpful posts as answer.

    • Marked as answer by NANDAKUMAR T Monday, February 16, 2015 12:26 PM
    Monday, February 16, 2015 11:58 AM