Interview Tips Interview Tips, Interview Questions and Answers

16May/100

.NET Object Serialization – How can I optimize the serialization process?

How can I optimize the serialization process?

The first call to a Web Service takes long because XmlSerializer generate an assembly optimized for each type in memory.

To optimize the serialization process pregeneration of serialization assembly with Visual Studio or sgen.exe is needed.

Implementing serialization separately can also increase the performance.

What is Formatters? Explain the binary formatter and the SOAP formatter.

A formatter determines the serialization format for objects.

.NET framework provides Binary formatter and SOAP formatter which inherit from the IFormatter interface

The Binary Formatter

It provides binary encoding for compact serialization for storage or socket-based network streams.
It is not appropriate for data to be passed through a firewall.

The SOAP Formatter

It provides formatting that can be used to enable objects to be serialized using the SOAP protocol.
The class is used for serialization through firewalls or diverse systems.

18Apr/100

.NET interview: Serialization in .NET

Explain about Serialization in .NET. Explain binary serialization and XML serialization

System.Runtime.Serialization namespace provides Serialization in .NET.
The IFormatter interface in the namespace contains Serialize and De-serialize methods that save and load data of a stream.
So we need stream as a container for the serialized object(s) and a formatter that serializes these objects onto the stream to implement serialization in .net.

Binary serialization is a mechanism that creates exact binary copy of the object onto the storage media by writing the data to the output stream such that it can be used to re-construct the object automatically.

XML serialization results in strongly typed classes with public properties and fields that are converted to a serial format for storage or transport. This XML stream conforms to a specific XML Schema definition language (XSD) document.

Explain why Serialization.

An object is stored in a file, a database or even in the memory. However, data to be transferred over a network needs to be in a linear form for which serialization and deserialization are used.

Advantage of serialization is the ability of an object to be serialized into a persistent or a non-persistent storage media and then reconstructing the same object later by de-serializing the object.

Remoting and Web Services depend heavily on Serialization and De-serialization.

Explain the components that comprise the binary serialization architecture.

To binary serialize an object we need a FileStream object,
Constructor: FileStream(file_name, FileMode.Create);

And

BinaryFormatter
Constructor: binaryFormatter.Serialize(fileStreamObject, object1);

What is Formatters? Explain the binary formatter and the SOAP formatter.

A formatter determines the serialization format for objects.

.NET framework provides Binary formatter and SOAP formatter which inherit from the IFormatter interface

The Binary Formatter

It provides binary encoding for compact serialization for storage or socket-based network streams.
It is not appropriate for data to be passed through a firewall.

The SOAP Formatter

It provides formatting that can be used to enable objects to be serialized using the SOAP protocol.
The class is used for serialization through firewalls or diverse systems.

24Jan/100

What is the use of serializable keyword in C#?

Marking a class with the key word [Serializable] at the top ensures that the object can be serialized in an XML format primarily for data exchange between disparate systems.  Also, this is required if this object is going to be inherited by other objects which needs to be serialized downstream.

Serializable is a concept of converting your user define type i.e. class into bytes. Serializing object into bytes help for ease in transporting data within network or machines. .Net also provides support to desializing

We can do Serializing in following ways:
i. XmlSerializer.
ii. Soap Formatter and Binary formatter.