I am trying to create a class with a read-only Id field, however I am having problems retaining the value when the object passes through the WCF server.
I cannot set the [DataMember]
attribute on the public property since there is no set
method, and I would like to keep it that way if possible since I do not want this value changed by external means. I cannot set the [DataMember]
attribute on the private field since it throws an error in partial trust environments.
public class MyClass
{
private int _id;
public int Id
{
get { return _id; }
}
private string _otherProperties;
[DataMember]
public string OtherProperties
{
get { return _otherProperties; }
set { _otherProperties = value; }
}
}
Is there a way to maintain the value of the Id field while going through the WCF server without making my property public?