Difference between DataContractSerializer vs XmlSerializer

后端 未结 2 1164
抹茶落季
抹茶落季 2021-02-04 11:06

I was going through WCF Fundamentals, Can anybody tells that under which scenarios should we use DataContractSerializer and XmlSerializer?

2条回答
  •  悲哀的现实
    2021-02-04 11:57

    DataContractSerializer

    • Is meant to be used for serialization/deserialization of class in WCF service to and from either JSON or XML.
    • serializes properties and fields.
    • Is faster than XmlSerializer
    • Doesn't control how xml is generated. Should not be used when full control on generated XML structure is required

    XMLSerializer

    • XmlSerializer is only for XML serialization
    • Supports full control over the XML structure
    • Serializes only public properties

提交回复
热议问题