Monday 2 January 2012

Remoting


What is an application domain?
Previously "PROCESS" where used as security boundaries. One process has its own virtual memory and does not over lap the other process virtual memory; due to this one process can not crash the other process. So any problem or error in one process does not affect the other process. In .NET they went one step ahead introducing application domains. In application domains multiple applications can run in same process with out influencing each other. If one of the application domains throws error it does not affect the other application domains. To invoke method in a object running in different application domain .NET remoting is used.
What is an application domain?
.NET remoting is replacement of DCOM. Using .NET remoting you can make remote object calls which lie in different Application Domains. As the remote objects run in different process client calling the remote object can not call it directly. So the client uses a proxy which looks like a real object. When client wants to make method call on the remote object it uses proxy for it. These method calls are called as "Messages". Messages are serialized using "formatter" class and sent to client "channel". Client Channel communicates with Server Channel. Server Channel uses as formatter to deserialize the message and sends to the remote object.
Which class does the remote object has to inherit?
All remote objects should inherit from System.MarshalbyRefObject.
What are two different types of remote object creation mode in .NET?
There are two different ways in which object can be created using Remoting :-
1. SAO (Server Activated Objects) also called as Well-Known call mode.
2. CAO (Client Activated Objects)
SAO has two modes "Single Call" and "Singleton". With Single Call object the object is created with every method call thus making the object stateless. With Singleton the object is created only once and the object is shared with all clients. CAO are stateful as compared to SAO. In CAO the creation request is sent from client side. Client holds a proxy to the server object created on server.
What are the situations you will use singleton architecture in remoting?
If all remoting clients have to share the same data singleton architecture will be used.
How can we call methods in remoting Asynchronously?
All previous examples are a synchronous method calls that means client has to wait until the method completes the process. By using Delegates we can make Asynchronous method calls.
What is Asynchronous One-Way Calls?
One-way calls are a different from asynchronous calls from execution angle that the .NET Framework does not guarantee their execution. In addition, the methods used in this kind of call cannot have return values or out parameters. One-way calls are defined by using [OneWay()] attribute in class.
What is marshalling and what are different kinds of marshalling?
Marshaling is used when an object is converted so that it can be sent across the network or across application domains. Unmarshaling creates an object from the marshaled data. There are two ways to do marshalling :-
1. Marshal-by-value (MBV) - In this the object is serialized into the channel, and a copy of the object is created on the other side of the network. The object to marshal is stored into a stream, and the stream is used to build a copy of the object on the other side with the unmarshalling sequence.
2. Marshaling-by-reference (MBR)- Here it creates a proxy on the client that is used to communicate with the remote object. The marshaling sequence of a remote object creates an ObjRef instance that itself can be serialized across the network. Objects that are derived from "MarshalByRefObject" are always marshaled by reference. All our previous samples have classes inherited from "MarshalByRefObject" To marshal a remote object the static method RemotingServices.Marshal() is used. RemotingServices.Marshal() has following overloaded versions:-
1. public static ObjRef Marshal(MarshalByRefObjectobj)
2. public static ObjRef Marshal(MarshalByRefObject obj, string objUri)
3. public static ObjRef Marshal(MarshalByRefObject obj, string objUri,Type requestedType)

The first argument obj specifies the object to marshal. The objUri is the path that is stored within the marshaled object reference; it can be used to access the remote object. The requestedType can be used to pass a different type of the object to the object reference. This is useful if the client using the remote object shouldn't use the object class but an interface that the remote object class implements instead. In this scenario the interface is the requestedType that should be used for marshaling.
What is ObjRef object in remoting?
All Marshal() methods return ObjRef object.The ObjRef is serializable because it implements the interface ISerializable, and can be marshaled by value. The ObjRef knows about :-
1. location of the remote object
2. host name
3. port number
4. object name.


No comments:

Post a Comment