Вы находитесь на странице: 1из 32

REMOTING

Remote Action Concepts


AppDomain B

AppDomain A
Remote Action
Object a

Object b

Introduction
AppDomain
An isolated environment for executing code
Local Objects
Objects within the different AppDomains
Remote Objects
AppDomain A
AppDomain B
Objects in a different AppDomain
Remoting
Obj1
Remoting Obj3
Communication between objects

Obj 2

Obj 4

.NET Remoting Concepts


The Two types of marshal objects are as follows
By reference:Inherits from Marshal By RefObject class
By Value:Declares the system to serialize the object
automaticaly.Attributes methods for class and field.
Example
<Serializable()>
<NonSerialized()>
/Serializable methods
Example
GetObjectData()
Deserialized()

Remote Activation Concepts

Processes
Isolates the application from other applications

01

03
02

04
06
05

Process 1
Process 2

Remote Activation Concepts(Contd)


Marchal by reference object

Oa
Ob
Proxy

Client

Ob

Server

RemoteActivationConcepts(Contd)
Marchal by value object

Oa

Ob

Ob

Client

Server

Types of .NET Remote Objects


The two types of activation for marchal by reference objects are as
follows
Server Activation
Objects are Created by the Server.
The two types of server-activated objects are as follows.
Singleton
Singlecall
Client Activation
Objects are created when the new method is invoked.
The two types of Client-activated objects are as follows
Marshal by reference
Marshal by value

Activation

Client

Server

Singleton

Singlecall

Marshal by
Reference

Marshal
by Value

Types of .NET Remote Objects(Contd)


Server-activated singleton
The objects have only one instance for all clients

Ca
Cb
Proxy

Cb

Client A
Ca
Server
Cb
Proxy
Client B

Types of .NET Remote Objects(Contd)


Server-activated single call
New instances of object are created for every user

Ca
Cb
Proxy
Client A
Ca
Server
Cb
Proxy
Client B

Types of .NET Remote Objects(Contd)


Client-activated Marshal by reference objects
Each client gets its own remote object

Ca
Cb
Proxy

Cb
Cb

Client A
Ca
Server
Cb
Proxy
Client B

Types of .NET Remote Objects(Contd)


Client-activated Marshal by value objects
Clients get their own copy of the objects

Ca
Cb

Cb

Client A
Ca
Server
Cb
Client B

Hosting Remote Objects


Server
Server
Server

Client
Client
(Remote object)
object)
(Remote

Remoting Architecture in .NET


Client-Side Object

Server-side Object

Server

Client

Proxy
TCP/HTTP
Formatting
Formatting

Channel

Hosting .NET Remote Object


Microsoft Internet Information Services(IIS) is a run-time environment
to host the remote objects.
The steps involved in hosting a remote object are as follows.
1.
Client object registers a channel.
2.
Creates a proxy object.
3.
Calls the remote method.
4.
Client-side formatter formats the message and transmits it to the
Server-side.
5.
Server-side formatter reformats the message.
6.
The specified function on the remote object is executed and the
results are obtained.
7.
The same process of formatting and reformatting is reversed and
the result is obtained.
Client-side
Object

Formatter or
Reformatte
r

Sever-side Object

Server Config File


<?Xml version=1.0 encoding=utf-8?>
<Configuration>
<system.runtime.remoting>
<debug lode types=true/>
<application name=RemoteHost>
<channels>
<channel ref=tcp port=8085/>
<channel ref=http port=8086/>
</channels>
<service>
<Wellknown mode=Singletone
type=RemoteObjects.SingletonRef.RemoteObject
ObjectUri=SingleCallByRefHost.rem/>
<Activated type=RemoteObjects.ClientActivatedByRef.RemoteObjects/>

</Service>
</Application>
<System.runtime.remoting>
</Configuration>

Server Configuration in Code


ChannelServices.RegisterChannel(New TcpChannel(8085))
ChannelServices.RegisterChannel(New HttpChannel(8086))
RemotingConfiguration.RegisterWellKnownServiceType
(GetType(SingletonByRef),SingletonByRefHost.rem,Singleton)
RemotingConfiguration.RegisterWellKnownServiceType
(GetType(SinglecallByRef),SingletonByRefHost.rem,Singlecall)
RemotingConfiguration.RegisterActivatedServiceType
(GetType(ClientActivatedByRef))

Server Configuration
RemotingServices.Marshal(New
SingletonByRef(),SingletonByRefHost.rem)
Remoting Server
Singleton
BYRef
TCP:8085

HTTP:8086

Internal Remoting
Configuration
Tables

Client Config File


<?Xml version=1.0 encoding=utf-8?>
<Configuration>
<system.runtime.remoting>
<debug lode types=true/>
<application name=RemoteClient>
<client url=tcp://localhost:8085/RemoteHost>
<wellknown type=RemoteObjects.SingletonByref,RemoteObjects
url=tcp://localhost:8085/RemoteObjects.SingletonByRefHost.rem/
>
<wellknown type=RemoteObjects.SingleCallByref,RemoteObjects
url=http://localhost:8085/RemoteObjects.SingleCallByRefHost.rem
/>
<activated
type=remoteObjects.ClientActivatedByref,remoteObjects/>

</client>
</application>
</system.runtime.remoting>
</configuration>

Client Configuration in Code


ChannelServices.RegisterChannel(New TcpChannel(8085))
ChannelServices.RegisterChannel(New HttpChannel(8086))
RemotingConfiguration.RegisterWellKnownServiceType
(GetType(SingletonByRef),tcp://localhost:8085/RemoteHost/Singlet
oneByRefHost.rem)
RemotingConfiguration.RegisterWellKnownServiceType
(GetType(SinglecallByRef),http://localhost:8086/RemoteHost/Single
CallByRefHost.rem)
RemotingConfiguration.RegisterActivatedClientType
(GetType(ClientActivatedByRef), tcp://localhost:8085/RemoteHost)

Client Configuration
Remoting Client

TCP
Internal
Remoting
Configurati
on Tables

HTTP

Creating Remote Objects


Singleton and singlecall functions
Now()(default constructor only)
Activator.CreateInstance()
Activator.GetObject()
remotingServices.Connect()

Client A
Proxy

Client B

Server

Creating Remote Objects(Contd)


Client-activated marshal by reference functions
Now()(default constructor only)
Now()(Non-default constructor only)
Activator.CreateInstance()
Return value from function
Returned in ByRef argument
Client-activated marshal by value
It cannot be created directly.
Client A

Client B

Object b

Object b

Server

Remote Object Lifetime


The AppDomain class contains a lease manager that examines the
leases for time expiration.
The features of leases for remote objects are as follows:
Applies only to the singleton and marshal by reference clientactivated objects.
Initializes when the object is created.
Avoids the changes that are done after intialization.
Marks the expired objects for garbage collection.
Example
leaseObj=remotingServices.GetLifetimeservice(obj)

Remote Object lifetime(contd)


ILease interfaces
They are used to define
InitialLeaseTime
RenewOncallTime
SponsorshipTimeout
CurrentState

Initial
Active
Expired
Renewing

a lifetime lease object.


-default:5minutes
- default:2minutes
- default:2minutes
Lifetime-Object
Interface
Lifetime-ILease

Remote Object Lifetime(Contd.)


<?Xml version=1.0 encoding=utf-8?>
<Configuration>
<system.runtime.remoting>
<debug lode types=true/>
<application name=RemoteHost>
<!- Change AppDomain Lease details-->
<lifetime lease Time=6m
renewOnCallTime=3m
Sponsorship Timeout=3m
leaseManagePollTime=11ms/>
<channels>
<channel ref=tcp port=8085/>

<channel ref=http port=8085/>


</channels>
</application>
</system.runtime.remoting>
</configuration>

Remote Object Lifetime(Contd.)


Override initializeLifetimeService method
The features of overriding initializeLifetimeService method are as
follows:
Inherited from MarshalByRefObject.
Used to initialize lease on specific object.
Extending the lease
The methods to extend the lease are as follows:
RenewOncallTime should be nonzero
Call.Renew(Time) method
Register a sponsor on the lease

THANK YOU

Вам также может понравиться