1
HO CHI MINH UNIVERSITY OF INDUSTRY
.NET
Remoting
2
HO CHI MINH UNIVERSITY OF INDUSTRY
Net Remoting Definition:
• Application which is located in another
application domain or process can
communicate with another by using .Net
Remoting.
• Net Remoting allows processes to share
the objects. It can call the method and can
access the properties of an objects that
are:
3
HO CHI MINH UNIVERSITY OF INDUSTRY
Hosted in different application domain
with in the same process or
Different process executing on same
computer or
Different computers connected by LAN
or
Different computer distributed over world
wide
4
HO CHI MINH UNIVERSITY OF INDUSTRY
Modern applications are no longer stand-alone
applications.
.NET Remoting:
- Provides a solution for
communication between
application domains
5
HO CHI MINH UNIVERSITY OF INDUSTRY
You known Application Domain ?:
Application domain is the collection of
classes, which isolate these from other
applications. The application in one
application domain could not access the
application in other application domain
(without using Remoting)
6
HO CHI MINH UNIVERSITY OF INDUSTRY
2 Object type
• It can be accessed outside
its application domain.
Remotable
Object
Non
Remotable
Object
CLR objects cannot, by default, be
used outside their AppDomain
- No way to copy them
- No way to reference them
Exception occurs when you try to
pass an object reference to a
different domain
SO: It can not be accessed outside
its own application domain.
7
HO CHI MINH UNIVERSITY OF INDUSTRY
Remotable Object:
Can request that instances of a class be
accessible outside original AppDomain
– Client get a copy of the object
– Client get a reference (proxy) to the
original object
When an object is Remotable?
The object should inherit the class
System.MarshalByRefObject
Two Types of Remotable Objects are there
– Marshal by Value
– Marshal by Reference
*More detail later
8
HO CHI MINH UNIVERSITY OF INDUSTRY
Object Serialization:
Conversion of an object (instance) into a data
stream of bytes, Serialization is a method of
persisting objects for storage in a database, to
various media, or during marshaling—the
process of moving an object to a new
application domain, context, process, or
system. Serialization is performed by the
Common Language Runtime (CLR).
9
HO CHI MINH UNIVERSITY OF INDUSTRY
MarshalByRef objects:
When the object's class derives, directly or
indirectly, from MarshalByRefObject, the
runtime creates a proxy to the object
[Serializable]
class Foo : System.MarshalByRefObject
{
. . .
}
Clients in foreign AppDomains receive
proxy
How does a client specify what proxy?
10
HO CHI MINH UNIVERSITY OF INDUSTRY
Serializable objects:
When runtime can make a copy of the object,
an object can marshal-by-value to other
AppDomains
– Add SerializableAttribute
– Or implement the ISerializable interface
[Serializable]
Class Far {
. . .
}
11
HO CHI MINH UNIVERSITY OF INDUSTRY
Remoting in general :
Clients must connect to servers
Server needs to publish an object
• I listen on this TCP channel and that HTTP
channel
• I have a service called "MathService"
• When client connects to MathService using
a supported channel, give the client [ a | this ]
Calculator instance
Clients need to specify the desired object
• Connect to the "MathService" on server
"LightningFast" using protocol HTTP on port 80
12
HO CHI MINH UNIVERSITY OF INDUSTRY
ASP.NET Web services (WS)
vs
.NET Remoting (NR)
See next slide…
13
HO CHI MINH UNIVERSITY OF INDUSTRY
1. WS: only be accessed over HTTP; NR
various protocols like TCP, HTTP etc.
2. WS stateless environment, NR state
management
3. WS more reliable than .NET Remoting.
4. WS are easy to create and use, NR are
complex to be created.
5. WS across platforms, NR requires client
to be built using .NET
6. WS support datatypes defined in the XSD
type system while .NET remoting provides
support for rich type system using binary
communication.
14
HO CHI MINH UNIVERSITY OF INDUSTRY
.Net Remoting components
A remotable object.
A host application.
– listen to requests for the hosted
remotable object.
A client application.
– requests for the remotable object.
15
HO CHI MINH UNIVERSITY OF INDUSTRY
How Does .NET Remoting Works?
In the client
– create a new remotable object
=>creates a proxy object
– When client call method => call method on
proxy=> server=> return to proxy => client
16
HO CHI MINH UNIVERSITY OF INDUSTRY
Proxy
To avoid conjunction in networking. It
contains reference to all methods and
properties of object. There are two type of
proxy.
– Transparent proxy (There is no physical
existence, Created by IISserver)
– Real Proxy (Physical Existence)
17
HO CHI MINH UNIVERSITY OF INDUSTRY
Remoting makes an object in server
available to code in client => marshalling
2 ways to marshal an object
– Marshal by value
• the server creates a copy of the object
passes the copy to the client
– Marshal by reference
• the client creates a proxy for the object
and then uses the proxy to access the
object
18
HO CHI MINH UNIVERSITY OF INDUSTRY
Marshal by reference
2 types
– Server-Activated Objetcs (SAO)
– Client-Activated Objects (CAO)
Client-Activated Object:
– Server side object creation is handled by client application.
– An instance of object is created, when the client calls the new
operator.
Server-Activated Object:
– The object is created, when the client actually invoke a
method on proxy.
– Single Call (stateless)
• This object handles one and only one request coming from
client.
– Singleton
• This can be used to retain the state across multiple
method calls.
19
HO CHI MINH UNIVERSITY OF INDUSTRY
SAO - CAO
Server-Activated
• lifetime is controlled by server
• Use when there are clients sharing the same server
object
• It’s a one-to-many relationship between the server
object and clients
– Singleton – SingleCall Is called: WellKnow object
Client-Activated Objects
• lifetime is controlled by the client
• Use when multiple server instances of the same kind
need to be run on the server at the same time
• one-to-one relationship between each server object
and its corresponding client
20
HO CHI MINH UNIVERSITY OF INDUSTRY
Client-activated objects
Client-activated objects. Each
client gets an independent
object for its use. Like the
classic client-server model,
clients can still share objects.
21
HO CHI MINH UNIVERSITY OF INDUSTRY
Server-activated objects:
Singlecall
Singleton
Obj 3
Obj 1
Obj 2
Obj 4
Obj
n
Obj
A
Share
Share
Share
22
HO CHI MINH UNIVERSITY OF INDUSTRY
Terms using in .Net Remoting
Channel
Formatters
23
HO CHI MINH UNIVERSITY OF INDUSTRY
Channel:
The medium through the which the
messages would be transferred
The remote objects are to communicate
with one another and channels do this
transport job of communication.
The two existing channels
– HttpChannel and TCPChannel
24
HO CHI MINH UNIVERSITY OF INDUSTRY
HTTPChannel
– use SOAP Formatter to serialize
messages into the XML format using SOAP
protocol. Using SOAP method allows the
client to call method on the remote object
that might not be using .Net framework.
TCPChannel
– use binaryFormatter to serialize message
into binary stream.
Channel:
25
HO CHI MINH UNIVERSITY OF INDUSTRY
Channel:
We have to register at least one channel to use with
the remoting infrastructure before being able to call
the Remotable type from the client application.
We can register a channel in one of two ways:
– By “ChannelServices.RegisterChannel”, or
– By using a configuration file.
We have to choose a specific port for your channel
to listen on.
If we are not sure whether a port is available or not,
use 0 (zero)
When you configuring your channel’s port and the
remoting system will choose an available port for
you.