locked
how to command serializer not to put k__backingfield RRS feed

  • Question

  • In my wcf service I reference a dll that access a database and returns data from the database as list and I want to know how do I remove the k_backing field?
    Monday, November 15, 2010 2:41 AM

Answers

  • Hello, are you using XmlSerializer or DataContractSerializer? XmlSerializer serialize fields rather than properties. So it is likely your service will expose the k_backing fields rather than properties. XmlSerializer will be used if the data class has a Serializable attribute. Without this attribute, DataContractSerializer will be used (starting from .NET 3.5 SP1, you don't have to add DataContract/DataMember attributes as pointed out in the above link). DataContractSerializer serializes properties instead of fields, so it should work fine.

    We recommend you to use DataContractSerializer (default) as its performance is better. If you have to use XmlSerialzer, then please do not use properties. Design the data class to use well named fields.


    Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by Yi-Lun Luo Monday, November 22, 2010 2:07 AM
    Wednesday, November 17, 2010 1:30 AM

All replies

  • Hello, are you using XmlSerializer or DataContractSerializer? XmlSerializer serialize fields rather than properties. So it is likely your service will expose the k_backing fields rather than properties. XmlSerializer will be used if the data class has a Serializable attribute. Without this attribute, DataContractSerializer will be used (starting from .NET 3.5 SP1, you don't have to add DataContract/DataMember attributes as pointed out in the above link). DataContractSerializer serializes properties instead of fields, so it should work fine.

    We recommend you to use DataContractSerializer (default) as its performance is better. If you have to use XmlSerialzer, then please do not use properties. Design the data class to use well named fields.


    Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by Yi-Lun Luo Monday, November 22, 2010 2:07 AM
    Wednesday, November 17, 2010 1:30 AM