in Education by

Explain what is DataContractSerializer?

1 Answer

0 votes
by

WCF provides a message-oriented programming framework. We use WCF to transmit messages between applications. Internally WCF represents all the messages by a Message class. When WCF transmits a message it takes a logical message object and encodes it into a sequence of bytes. After that WCF reads those bytes and decodes them in a logical object. The process forms a sequence of bytes into a logical object; this is called an encoding process. At runtime when WCF receives the logical message, it transforms them back into corresponding .Net objects. This process is called serialization.

DataContractSerializer

WCF supports three basic serializers:

  • XMLSerializer
  • NetDataContractSerializer
  • DataContractSerializer

WCF deserializes WCF messages into .Net objects and serializes .Net objects into WCF messages. WCF provides DataContractSerializer by default with a servicecontract. We can change this default serializer to a custom serializer like XMLSerializer.

  1. [XmlSerializerFormat]  
  2. [ServiceContract]  
  3. public interface IService1  
  4. {  
  5.    [OperationContract]  
  6.    void AddAuthor(Author author);  
  7. }  

The XmlSerializerFormat attribute above the ServiceContract means this serializer is for all operation contracts. You can also set a separate contract for each operation.

XMLSerializer

We can find XMLSerializer in the System.Xml.Serialization namespace. WCF supports this serialization from .Net 1.0. It is used by default with the ASP.Net webservices (ASMX).

NetDataContractSerializer

NetDataContractSerializer is analogous to .Net Remoting Formatters. It implements IFormatter and it is compatible with [Serializable] types. It is not recommended for service oriented design.

DataContractSerializer

DataContractSerializer is a default serializer for WCF. We need not to mention DataContractSerializer attribute above the service contract.

Related questions

0 votes
    What is Duplex in WCF? Explain also Message Exchange Pattern?...
asked Apr 3, 2021 in Education by JackTerrance
0 votes
    Explain bindings in WCF with description?...
asked Apr 3, 2021 in Education by JackTerrance
0 votes
    Explain briefly different Instance Modes in WCF?...
asked Apr 3, 2021 in Education by JackTerrance
0 votes
    What Message Exchange Patterns (MEPs) supported by WCF? Explain each of them briefly....
asked Apr 3, 2021 in Education by JackTerrance
0 votes
    Explain transactions in WCF?...
asked Apr 2, 2021 in Education by JackTerrance
0 votes
    What is Information cards in WCF?...
asked Apr 3, 2021 in Education by JackTerrance
0 votes
    What is Instance Management in WCF?...
asked Apr 3, 2021 in Education by JackTerrance
0 votes
    What is the concept of tracelevel in trace listeners?...
asked Apr 3, 2021 in Education by JackTerrance
0 votes
    What you understand by Fault Exception in WCF?...
asked Apr 3, 2021 in Education by JackTerrance
0 votes
    What is WCF Messaging Layer?...
asked Apr 3, 2021 in Education by JackTerrance
0 votes
    What is Method overloading in WCF?...
asked Apr 3, 2021 in Education by JackTerrance
0 votes
    What is MSMQ in WCF?...
asked Apr 3, 2021 in Education by JackTerrance
0 votes
    What is Transport level security in WCF?...
asked Apr 3, 2021 in Education by JackTerrance
0 votes
    What is SOA, and Messages in WCF?...
asked Apr 3, 2021 in Education by JackTerrance
0 votes
    What is Streaming in WCF?...
asked Apr 3, 2021 in Education by JackTerrance
...