As many of you will be aware, I can use the DataContract attribute to mark a class for serialization into XML in a WCF service.
For example, I can create a DataContract thus:
< DataContract() > Public Class fooClass
< Datamember() > Public fooString as String
End Class
When I add a service reference to the code that will receive this DataContract, I see that the class generated by the designer has fooString as a public property with a backing field. My question is, why does the designer use a backing field? I don’t see any reason not to access fooString directly.
It is code design “standard” style used by MS. And is for a good reason to use
propertiesinstead ofpublic fields. Even if on server side you will have data contract like this :In client proxy class you will have them as backing fields named something like
idField,nameField…So it is not connected to WCF itself it is matter of why to use
propertiesinstead ofpublic fieldsfor which you can easily find guidance.