WCF “k__BackingField” Property Naming
While I was working on a project that involved designing WCF services as Backend layer, I ended up defining a class
[Serializable]
public class ProgramDetails
{
public string ProgramName { get; set; }
}
When this WCF service is exposed, there is a little different behavior in the naming of this Class and its Members.
When serializing these objects, the serializer will look at all FIELDS of the class no matter their scope: public, private, etc. This is because it uses System.Runtime.Serialization, not System.Xml.Serialization.
What happens as a result is - suffix k__BackingField added to each property. That is ProgramName becomes ProgramNamek__BackingField. This is really annoying to see such cryptic thing. So how do we resolve it?
Its simple! Modify your code to-
[DataContract]
public class ProgramDetails
{
[DataMember]
public string ProgramName { get; set; }
}
System.Runtime.Serialization, the serializer will interpret your DataMembers as fields on the class and use your naming. So what you see is ProgramName and not ProgramNamek__BackingField