WHAT'S NEW?
Loading...

Day 18 Programming in C# 70-483

Index


  • Introduction
  • XML serializer
  • Binary serializer
  • DataContract serializer
  • JSON serializer
  • References

Introduction

This post is part of a series of post to help you prepare the MCSD certification, particularly the certification exam 70-483, based on the book:


You will find all the code available in the following GitHub repository. Lets talk a little bit about threads and how they work using a .Net development environment.

XML serializer

Serialization is about transformation in order to send information. When you want to send data to a web service first you transform that data to a flat or binary form, send it and then you transform back that data. When you want to define what data you want to serialize, typically a DTO (Data transfer object) is created where you define all the properties you want to send.

Features:
  • XmlSerializer class
  • Simple Object Access Protocol (SOAP)
  • Not the best performance
  • Can't do private fields
  • Decoration:
    • class: [Serializable]
    • properties: by default members are serialized as XmlElement, ie, as nodes.
      • [XmlIgnore]: not serialize
      • [XmlAttribute]
      • [XmlElement]
      • [XmlArray]: for collections
      • [XmlArrayItem]: for collections

Binary serializer

This type of serializer is used more commonly with images and non-readable data. 

Features:
  • BinarySerializer class
  • namespaces: System.Runtime.Serialization and System.Runtime.Serialization.Formatters.Binary
  • Private fields are serialized by default
  • Decoration:
    • class: [Serializable]
    • properties:
      • [NonSerialized]
    • methods:
      • [OnDeserializedAttribute]
      • [OnDeserializingAttribute]
      • [OnSerializedAttribute]
      • [OnSerializingAttribute]
  • ISerializable: by implementing this you can define what is serialized, and if you have sensitive data you can encrypt prior to serialization. Implement:
    • GetObjectData(): called when your object is serialized. You can decorate it with a SecurityPermission attribute, so it is allowed to serialize and deserialize
    • protected constructor: called when you object is deserialized. You use it to retrive the values and build your object by defining 

DataContract serializer

Features:
  • DataContractSerializer class
  • It's used by WCF to serialize to XML or JSON
  • Decoration:
    • class: [DataContract]
    • operations: [DataMember]
    • methods:
      • [OnDeserializedAttribute]
      • [OnDeserializingAttribute]
      • [OnSerializedAttribute]
      • [OnSerializingAttribute]

JSON serializer

Features:
  • DataContractJsonSerializer class
  • small amounts of data
  • It uses Asynchronous JavaScript and XML (AJAX)

0 comments:

Post a Comment