I have some class that I\'m passing as a result of a service method, and that class has a get-only property:
[DataContract]
public class ErrorBase
{
[DataM
Even if you dont need to update the value, the setter is used by the WCFSerializer to deserialize the object (and re-set the value).
This SO is what you are after: WCF DataContracts
If it's a viable option, then instead of having ErrorBase
as the base class, define it as follows:
public interface IError
{
string Message
{
[OperationContract]
get;
// leave unattributed
set;
}
}
Now, even though a setter exists, it's inaccessible to the client via WCF channel, so it's as if it were private.
If your serializer is of type DataContractJsonSerializer (or any DataContractSerializer) you can also use DataContractSerializerSettings in the constructor, with the SerializeReadOnlyTypes property set to true.
Couldn't you just have a "do-nothing" setter??
[DataContract]
public class ErrorBase
{
[DataMember]
public virtual string Message
{
get { return ""; }
set { }
}
}
Or does the DataContract serializer barf at that, too??
Properties with DataMember attribute always requires set. You should re write simmilar object on the client application since DataContract members can always be assigned values.
Give Message a public getter but protected setter, so that only subclasses (and the DataContractSerializer, because it cheats :) may modify the value.