- Datacontractserializer Attributes Xml
- C# Data Contract Serializer
- Data Contract Serializer Attributes Pdf
The Windows Communication Foundation (WCF) infrastructure uses the DataContractSerializer class as the default serializer. The topics in this section provide more details for using it as a stand-alone serializer.
In This Section
Serialization and Deserialization
Details how to use the DataContractSerializer class to serialize object graphs and deserialize XML documents into objects.
Details how to use the DataContractSerializer class to serialize object graphs and deserialize XML documents into objects.
The DataContractSerializer understands data contracts that have been designed to be compatible with future versions of the contract. Such types implement the IExtensibleDataObject interface. The interface features the ExtensionData property that returns an ExtensionDataObject object. For more information, see Forward-Compatible Data Contracts.
Schema Import and Export
Explains how to generate an XML Schema definition language (XSD) schema from a .NET Framework class, or how to generate code from an XSD schema document.
Explains how to generate an XML Schema definition language (XSD) schema from a .NET Framework class, or how to generate code from an XSD schema document.
Reference
Related Sections
See also
-->JSON (JavaScript Object Notation) is an efficient data encoding format that enables fast exchanges of small amounts of data between client browsers and AJAX-enabled Web services.
This article demonstrates how to serialize .NET type objects into JSON-encoded data and then deserialize data in the JSON format back into instances of .NET types. This example uses a data contract to demonstrate serialization and deserialization of a user-defined
Person
type and uses DataContractJsonSerializer.Datacontractserializer Attributes Xml
Normally, JSON serialization and deserialization are handled automatically by Windows Communication Foundation (WCF) when you use data contract types in service operations that are exposed over AJAX-enabled endpoints. However, in some cases you may need to work with JSON data directly.
Note
If an error occurs during serialization of an outgoing reply on the server or for some other reason, it may not get returned to the client as a fault.
This article is based on the JSON serialization sample.
To define the data contract for a Person type
- Define the data contract for
Person
by attaching the DataContractAttribute to the class and DataMemberAttribute attribute to the members you want to serialize. For more information about data contracts, see Designing service contracts.
To serialize an instance of type Person to JSON
- Create an instance of the
Person
type. Autocad 2007 manual pdf download. - Serialize the
Person
object to a memory stream by using the DataContractJsonSerializer. - Use the WriteObject method to write JSON data to the stream.
- Show the JSON output.
To deserialize an instance of type Person from JSON
- Deserialize the JSON-encoded data into a new instance of
Person
by using the ReadObject method of the DataContractJsonSerializer. - Show the results.
Example
Note
C# Data Contract Serializer
The JSON serializer throws a serialization exception for data contracts that have multiple members with the same name, as shown in the following sample code.