Object serialization and remoting

fortnecessityusefulΛογισμικό & κατασκευή λογ/κού

14 Δεκ 2013 (πριν από 3 χρόνια και 3 μήνες)

76 εμφανίσεις

lecture 5 slide 1


Serialization: Process of converting the state of an
object to a linear sequence of data is termed as
Serialization. This data sequence contains all
necessary information needed to reinstruct (or
deserialize) the state of the object for use later.

The .NET serialization services are quite
sophisticated: When a given object is serialized to a
stream, any associated object references required
by the root object are automatically serialized as

lecture 5 slide 2


Once a set of objects has been saved to a
stream, the data pattern can be relocated as
necessary. For ex., if you have serialized an
object group into memory location using the
system.IO.MemoryStream type. This stream
could be forwarded to a remote Computer,
the Windows Clipboard, burned to a CD, or
simply written to a physical file.

lecture 5 slide 3


Configuring Objects for Serialization:

1. To make an object available to .NET
serialization services, decorate each class with

the [serializable] attribute.

2. If you have some member data in a given
class that should not participate in the

serialization scheme, you can mark such fields
with the [Non Serialized] attribute

applicable for ex., for constants, transient
data etc.

lecture 5 slide 4


Ex. // The Radio class can participate in the .NET serialization


public class Radio

{ // this member will not be persisted.

[Non Serialized]

private int objectIDNumber = 9;

//Other Serialized state data.

public Radio( ) {}

public void On (bool state)


if (state = = true)

MessagBox.Show(“Music is on …”);


MessageBox.Show (“No tunes…”);



lecture 5 slide 5


Choosing a serilization formatter

The system run time serialization fromatters namespace
contains two additional nested namespaces (* Binary

The binary formatter type serializes your object graph to a
stream using a compact binary format.

The soap formatter type represents your graph as SOAP
(single object Access Protocol) message that is expressed
using XML data representation.

The system.Runtime.Serilization.Formatters.Binary.Binary
Formatter type is define within mscorlit.dll;

Ex: //persist object graph using a binary format!

lecture 6 slide 1


Choosing a serilization formatter

Using system.runtime.serizlization.formatters.binary;

The systm.runtime. Serilization.Formatters. Soap.Formatter
type is defined in a separate assembly. To format your
object graph in to a SOAP message, you must set a
reference to system.runtime.
Serilization.Formatters.Soap.all and make the following C++
using directive.

Ex: //persist object graph using a SOAP format!

Using system. runtime.serizlization.formatters.Soap;

lecture 6 slide 2


.NET Remoting

An application domain is a logical boundary for a .NET assembly
which is itself contained within a process type.

In the context of distributing computing under .NET, remoting is the
act of two pieces of s/w communicating across app.domains.

Possible scenarios for the app.domains:

Two app. domains in the same process (and thus on the same machine).

Two app.domains in separate process on the same machine.

Two app.domains in separate process on difference machines.

Regardless of the distance between two softwares entities, it is
common to refer to each agent using the terms client and server.

client is a piece of software that attempts to interact with a remote

server is the software agent that provides remote access to select

lecture 6 slide 4


The .NET Remoting namespaces:

The .NET base class libraries provide numerous
namespaces that allow you to build dist.apps.

The bulk of the types found with in these
namespaces are contained with in mscorlib.dll.

The system.Runtime.Remoting .dll assembly does
complement and extend the basic type set.

lecture 7 slide 1



Centric Namespace



Cure n/s, you must use when building any
sort of app. Using the .NET Remoting layer

System.Runtime.Remoting Activation

Small n/s, to fine

tune the
process activating a remote object.

System.Runtime.Remoting Channels

Types to represent channels and
channel links.

System.Runtime.Remoting Channels.Http

Types that use the HTTP
protocol to transport messages and objects to and from remote

System.Runtime.Remoting Channels tcp

Types that use the TCP
protocol to transport messages and objects to and from remote

lecture 7 slide 2


System.Runtime.Remoting contexts

to configure the details of a
object’s context.

System.Runtime.Remoting. lifetime

to manage the lifetime of remoting

System.Runtime.Remoting. Messaging

to create and transmit
message object.

System.Runtime.Remoting. Metadata

to customize the generation
and processing of SOAP formatting.

System.Runtime.Remoting. Metadata

types that represent the
XML scheme def.


useful for soapsuds.exe
command line tool services. to convert.NET metadata to and from
XML schema for the remoting infrastructure.


provide functionality for proxy

lecture 7 slide 3


The .NET Remoting Framework:

When clients and servers exchange information.
across app.

Boundaries, the CLR makes use of
several low
level primitives to ensure the entities in
question are able to communicate with each other
as transparently as possible.

The .NET Remoting layer revolves around a careful
orchestration that takes place between four key
players: Proxies, Messages, Channels and

lecture 7 slide 4


Proxies & Messages:

Like Java RI, CORBA and DCOM, the role of a .NET Proxy is to fool the
client into believing it is communicating with a local object in the

A proxy has the identical interface (i.e., members, properties, fields
etc) as the remote type it represents.

The proxy invoked directly by the client is termed the transparent
proxy. It is generated by CLR and ensures that the client has
provided the current

and type of parameters to invoke the
remote method. Transparent proxies cannot be modified or
extended programmatically.


. is packaged up into another CLR generated
type termed the message object