A formatter is used to determine the serialization format
for objects. In other words, it is used to control the serialization of an
object to and from a stream. They are the objects that are used to encode and
serialize data into an appropriate format before they are transmitted over the
network. They expose an interface called the IFormatter interface. IFormatter's
significant methods are Serialize and De-serialize which perform the actual
serialization and de-serialization. There are two formatter classes provided
within .NET, the BinaryFormatter and the SoapFormatter. Both these classes extend
the IFormatter interface.
The Binary Formatter
The Binary formatter provides support for serialization
using binary encoding. The BinaryFormater class is responsible for binary
serialization and is used commonly in .NET's Remoting technology. This class
is not appropriate when the data is supposed to be transmitted through a
firewall.
The SOAP Formatter
The SOAP formatter provides formatting that can be used to
serialize objects using the SOAP protocol. It is used to create a Soap envelop
and it uses an object graph to generate the result. It is responsible for
serializing objects into SOAP messages or parsing the SOAP messages and
extracting these serialized objects from the SOAP messages. SOAP formatters in
.NET are widely used by the Web Services.