Introduction
Microsoft .NET Remoting provides a rich and extensible framework for objects living in different AppDomains, in different processes, and in different machines to communicate with each other seamlessly. .NET Remoting offers a powerful yet simple programming model and runtime support for making these interactions transparent. In this article we will take a look at the different building blocks of the Remoting architecture, as well as explore some of the common scenarios in which .NET Remoting can be leveraged
.NET Remoting Objects
There are three types of objects that can be configured to serve as .NET remote objects. You can choose the type of object depending on the requirement of your application. This section explains the following objects in detail:
Single Call
Single Call objects service one and only one request coming in. Single Call objects are useful in scenarios where the objects are required to do a finite amount of work. Single Call objects are usually not required to store state information, and they cannot hold state information between method calls. However, Single Call objects can be configured in a load-balanced fashion.
Singleton Objects
Singleton objects are those objects that service multiple clients and hence share data by storing state information between client invocations. They are useful in cases in which data needs to be shared explicitly between clients and also in which the overhead of creating and maintaining objects is substantial.
Client-Activated Objects (CAO)
Client-activated objects (CAO) are server-side objects that are activated upon request from the client. This way of activating server objects is very similar to the classic COM coclass activation. When the client submits a request for a server object using "new" operator, an activation request message is sent to the remote application. The server then creates an instance of the requested class and returns an ObjRef back to the client application that invoked it. A proxy is then created on the client side using the ObjRef. The client's method calls will be executed on the proxy. Client-activated objects can store state information between method calls for its specific client and not across different client objects. Each invocation of "new" returns a proxy to an independent instance of the server type.
Passing Objects Using .NET Remoting
In .NET Remoting, objects can be passed from one application to another in the following ways:
As parameters in method calls
Example: public int myRemoteMethod (MyRemoteObject myObj)
Return Value of method calls
Example: public MyRemoteObject myRemoteMethod(String myString)
Values resulting from property or field access of a .NET component
Example: myObj.myNestedObject
For objects that are Marshal By Value (MBV), a complete copy of the object is made when the object is passed from one application to another.
For objects that are Marshal By Reference (MBR), a reference to the object is made when passed from one application to another. When the object reference (ObjRef) arrives in the remote application, it is turned into a "proxy" back to the original object.