Overview of Serialization in Silverlight

Serializing types using DataContractSerializer and DataContractJsonSerializer is supported in the Silverlight version 2.0 core runtime. Support for XmlSerializer is enabled by referencing the System.Xml.Serialization.dll extension assembly.

Serialization support in Silverlight 2.0 is based largely on Windows Communication Foundation (WCF) serialization technologies. But there are some differences described here that need to be known by developers of Silverlight applications.

Using Data Contracts

Silverlight 2.0 supports serializing data contract types into SOAP using DataContractSerializer and into JSON using DataContractJsonSerializer. The equivalent serialization support in WCF is described in Using Data Contracts and Support for JSON and Other Data Transfer Formats.

The following important distinctions exist between Silverlight 2.0 and WCF:

  • WCF data contracts can be specified by applying the DataContractAttribute to a type and DataMemberAttribute attributes to their members to indicate that they are to be serialized. This was an opt-in model for data contracts. Silverlight 2.0 supports this model, but also supports a simplified opt-out model, where these attributes can be omitted from the type and the members of the type to be serialized. The data contract is implicit in the sense that the visibility modifiers (public, private) used by the type determines whether it and its members are included in the data contract. In this model, the name of a member is used to identify it in the serialized representation. A new IgnoreDataMemberAttribute attribute can be used to opt-out a member that is public when required.
  • No ISerializable, XmlElement, Array of type XmlNode or IXmlSerializable types can be used in Silverlight 2.0 data contracts.

Using XmlSerializer

  • Silverlight 2.0 supports XmlSerializer. The equivalent serialization support in WCF is described in XML and SOAP Serialization.
  • In Silverlight 2.0, generating SOAP messages as described in the preceding document is not supported.

Using Message Contracts

  • Message contracts are supported in Silverlight 2.0. The equivalent WCF feature is described in Using Message Contracts.

Send comments about this topic to Microsoft.

Copyright © 2008 by Microsoft Corporation. All rights reserved.