NANDA KUMAR

NANDA KUMAR

  • NA
  • 22
  • 2.6k

Operations in the setter is not exposed in the client

Feb 16 2015 1:55 AM

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.