(B)What is a 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 application 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.
(B) What is .NET Remoting ?
.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.
(B) Which class does the remote object has to inherit ?
All remote object should inherit from System.MarshalbyRefObject.
(I) 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 :-
√ SAO (Server Activated Objects) also called as Well-Known call mode.
√ 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.
(A) Describe in detail Basic of SAO architecture of Remoting?
Remoting has atleast three sections :-
√ Common Interface which will be shared between them.
√ Server.
√ Client.
First important section is the common interface between Server and
Client.”InterFaceRemoting” project has the interface code.For sample project interface is
very simple with only two methods :- SetValue and GetValue.
(A) 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.
(A) What are the ways client can create object on server in CAO model ?
There are two ways by which you can create Client objects on remoting server
√ Activator.CreateInstance().
√ By Keyword “New”
. (A) Are CAO stateful in nature ?
Yes.In CAO remoting model client creates a instance on server and instance variable set
by client on server can be retrieved again with correct value.
(I) Is it a good design practice to distribute the implementation to
Remoting Client ?
It’s never advisable to distribute complete implementation at client , due to following
reasons :-
√ Any one can use ILDASM and decrypt your logic.
√ It’s a bad architecture move to have full implementation as client side as any
changes in implementation on server side you have to redistribute it again.
So the best way is to have a interface or SOAPSUDS generated meta-data DLL at client
side rather than having full implementation.
(A) What is LeaseTime,SponsorshipTime ,RenewonCallTime and
LeaseManagerPollTime?
In normal .NET environment objects lifetime is managed by garbage collector. But in
remoting environment remote clients can access objects which is out of control of garbage
collector.Garbage collector boundary is limited to a single PC on which framework is
running , any remote client across physical PC is out of control of GC (Garbage Collector).
This constraint of garbage collector leads to a new way of handling lifetime for remoting
objects , by using concept called as “LeaseTime”.Every server side object is assigned by
default a “LeaseTime” of five minutes.This leasetime is decreased at certain intervals.Again
for every method call a default of two minutes is assigned.When i say method call means
every call made from client.This is called as “RenewalOnCallTime”.
Let’s put the whole thing in equation to make the concept more clear.
Total Remoting object life time = LeaseTime + (Number of method calls) X
(RenewalTime).
If we take NumberOfMethodCalls as one.
Then default Remote Object Life Time = 5 + (1) X 2 = 10 minutes (Everything is in
minutes)
When total object lifetime is reduced to zero , it queries the sponsor that should the
object be destroyed.Sponsor is a object which decides should object Lifetime be
renewed.So it queries any registered sponsors with the object , if does not find any then
the object is marked for garbage collection.After this garbage collection has whole control
on the object lifetime.If we do not foresee how long a object will be needed specify the “SponsorShipTimeOut” value. SponsorShipTimeOut is time unit a call to a sponsor is
timed out. “LeaseManagerPollTime” defines the time the sponsor has to return a leasetime extension.
(A) Can Non-Default constructors be used with Single Call SAO? Twist :- What are the limitation of constructors for Single call SAO ?
Non-Default constructors can not be used with single call objects as object is created
with every method call, there is no way to define Non-default constructors in method
calls.
It’s possible to use Non-Default constructor with Client activated objects as both methods
:-
“NEW” keyword and “Activator.CreateInstance” provide a way to specify Non-Default
constructors.
(I) How can we call methods in remoting Asynchronously ?
All previous examples are synchronous method calls , that means client has to wait until
the method completes the process.By using Delegates we can make Asynchronous method
calls.
(A) 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.
(B) 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 :-
√ 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.
√ 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:-
public static ObjRef Marshal(MarshalByRefObject obj)
public static ObjRef Marshal(MarshalByRefObject obj, string objUri)
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.
(A) 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 :-
√ location of the remote object
√ host name
√ port number
√object name