Upload
vidhi-patel
View
410
Download
0
Tags:
Embed Size (px)
DESCRIPTION
Citation preview
.Net Remoting
Common distributed protocols are:RPC : Remote Procedure CallsDCOM : MS Distributed Object ModelCORBA : Common Object Request Broker ArchitectureRMI : Java Remote Invocation
Client
Remote Service
Client Requests remote process
Server runs the Service/process and returns the result
Not Secure for external networks
Remote Service
Distributed Application
Remote Service
Distributed systems are generally more scalable , more robust and increase availability of services
Application Domain
(Assembly)
Remote Objects
Remote Objects
Remote Objects
LocalObjects
.Net Remoting allows access to objects placed around a network.It has:•Communication channel•A formatter : This can be Binary encoded or XML encoded (SOAP)
Serialization
Communication Channel
Distributed Application
Application Domain
(Assembly) Remote Objects
LocalObjects
Communication Channel
Communication Channel
Formatter: BinaryFast but not as
compatible as XML
Formatter: XML (SOAP)
Highly compatible but not as fast
Remote Objects
Application Domain
(Assembly)
Remote Object
Typically dll
Remoting Overview
LocalObject
Invoke
Pass object/value
Get Result
Different Assemblies are used between Local and
remote Service
Application Domain
(Assembly)
Remote Service
Does the object persists?
Remote object lifetime
LocalService
Invoke
Pass object/value
Get Result
Application
Within Local Assembly
Local Objects
LocalObject
LocalObject
Pass By Value
Pass By Reference
Application Domain
(Assembly)
Public void myObject (myObjectClass obj){}
Public void myObject (ref myObjectClass obj){}
Formatter(Encoder)
Application Domain
(Assembly)
Remote Object
Remote Object System
LocalObject
Serialize
Encapsulate(SOAP)
Communicate
Desterilize
Decapsulate(SOAP)
Communicate
Application Remote Object
Remote Object Activation
Server Activated ObjectSingleton :All clients get the same instance of the server object. It can communicate with multiple clients . Life time is determined by lease based lifetime (Used for chats, community networks)Single Call :Is a type of object activation when object is discarded immediately after use. It is stateless.
Client activated objects These have a finite lease time , Once their lease time expires they are left for garbage collector. Each caller would get their copy of the object
Namespace used for remoting:System.Net :This include classes related to the networking elements of the distributed systemSystem.Runtime.Remoting : This includes classes for the remote aspects of the .NET framework , such as mechanism for remote communication between objectsSystem.Web.Services :This includes protocols relating to Web services such as those to HTTP and SOAP encapsulation
Remote Object
Marshaling
Local Object
Client object
Proxy
Remoting System Remoting System
Server Object
Client application domain Server application domain
Communication Channel
Serialization
Objects passed by reference or value for local objects . For remote it is not possible to pass by reference – Remote objects must be marshaled
Remote Object
Marshaling
Local Object
Client object
Proxy
Remoting System Remoting System
ShowCapital()
Client application domain Server application domain
Communication Channel
Serialization
Creates dll on server
aCountry
aCountry capital
capital
Remote Objectpublic class ShowCapital : MarshalByRefObject{ public ShowCapital() { } public string show ( string country) { } }
Remote Object
Object.dll
Marshaling
Local Object
Client object
Proxy
Remoting System Remoting System
ShowCapital()
Client application domain Server application domain
Communication Channel
Serialisation
Access public methods of
remotable obj
aCountry
aountry capital
capital
Remote Object
Object.dll
Marshaling
Local Object
Client object
Proxy
Remoting System Remoting System
ShowCapital()
Client application domain Server application domain
Communication Channel
Serialisation
We need object invocation.And channel configuration.Eg. TCP channel 1234 , firewalls should allow channel
Channels
• TCP Channel – Faster and more secure communication. Intended predominantly for intra-domain communication. Requires port activation for communication with external world
• HTTP Channel performed using HTTP/SOAP protocol. Good for external communication since it is implemented over HTTP/HTTPS and most firewalls allow HTTP calls through.
TCP Channel
Local Object
Client object
Proxy
Remoting System
Client application domain
Communication Channel
Server activation object
Channel=1234
Using System.Runtime.Remoting.Channel.HttpUsing System.Runtime.Remoting.Channel.Tcp
TcpChannel channel = new TcpChannel(1234)
ChannelServices.RegisterChannel(channel)
Makes sure channel is not used by other apps
Remote Object
Object.dll
Activation
Client object
Proxy
Remoting System Remoting System
ShowCapital()
Client application domain Server application domain
Communication Channel
Serialisation
Channels map onto TCP ports..Standard ports are:21-FTP23-TELNET56-DNS80-www110-POP 3>1024 : developer use
Activation
Client object
Proxy
Remoting System
Client application domain
Server Activation is typically used when objects do not required to maintain their state between method calls(Single Call ) or where there are multiple clients who call methods on the same object instance where the object maintains its state between function calls (singleton)
In a client activated object the client initiates the object and manages it for its lifetime.
Activation
Client object
Proxy
Remoting System
Client application domain
What’s the capital of Canada
Ottawa
SAO – Single call
Login Name: John
OKSend email to Bert
Ok
SAO – Singleton
Get data
Get data
Delete
CAO- Client Manages Lifetime
Registering Remote Object
• Client must have some understanding of the interface of the remote object.
• So the compiler has check accesses to remote object
ActivationRegistering remote object
Client object
Proxy
Remoting System
Client application domain
Object mode : this defines the server activation, such as SingleCall or SingletonWellKnownObjectMode.SingleCall
newClass.ShowCapitl
ShowCapital1
Remote Object
Object URI: This is the indicator that the clients use to locate the objectnewClass.ShowCapital
Assembly name: This defines the assembly in which the class is contained in.“ShowCapital1”
Type name : This defines the data type of the remote object.Typeof(newclass.ShowCapital)
Assembly
MethodClass
Activation
Client object
Proxy
Remoting System
Client application domainObject mode : this defines the server activation, such as SingleCall or SingletonWellKnownObjectMode.SingleCall
newClass.ShowCapital
Assembly : ShowCapital1
Remote Object
Object URI: This is the indicator that the clients use to locate the objectnewClass.ShowCapital
Assembly name: This defines the assembly in which the class is contained in.“ShowCapital1”
Type name : This defines that data type of the remote object.Typeof(newclass.ShowCapital)
Remote objects are registered using the RegisterWellKnownServiceType Parameters are (data type , assembly name , activation method) .eg:
RemotingConfiguration.RegisterWellKnownServiceType (typeof(newClass.ShowCapital),”ShowCapital1”, WellKnownObjectMode.SingleTon
Activation
Client object
Proxy
Remoting System
Client application domain
Remote Object
RemotingConfiguration.Configure(“myconfig.config”);
The remote object will not instantiate itself, the client is required to initialize it, or call a method. This is achieved by a client which knows the URI of the remote object and by registering the channel it prefers using GetObject :
TcpClientChannel channel = new TcpClientChannel();
ChannelServices.RegisterChannel(channel);ShowCapital sh=(ShowCapital)Activator.GetObject (typeof(newClass.ShowCapital), ”tcp://localhost:1234/ShowCapital”);
Client side
Client requires type information about the class when this client code is compiled.
1- With a reference to the assembly where the class is stored (use local dll).2- Using SOAPSUDS tool to extract metadata directly from the endpoint. SOAPSUDS connects to the endpoint and extracts the metadata, and generates an assembly or source code that is then used in the client compilation.3-By splitting the remote object into an implementation and interface class and then use the interface as a reference when compiling the client
Determining data type