Monday, July 11, 2005

Object Activation in .NET remoting

I have often been confused on when the 'new()' operator can be used for remote server activation? Can it be used only for CAO (client activated objects) or SAO (server activated objects) or for both?

The answer is that the 'new' operator can be used to activate any kind of remote object-both CAO and SAO. The only difference between GetObject/CreateInstance and 'new' is that the former allows you to specify a URL as a parameter, where the latter obtains the URL from the configuration. (I belive the 'new' operator can be used only when U have the remote object implementation on the client side?)

Another imp point regarding activation is that the remote object on the server is 'not' actually created when the 'new' operator or the GetObject() methods are called.

Here's a snippet of what MSDN says:

GetObject or new can be used for server activation. It is important to note that the remote object is not instantiated when either of these calls is made. As a matter of fact, no network calls are generated at all. The framework obtains enough information from the metadata to create the proxy without connecting to the remote object at all. A network connection is only established when the client calls a method on the proxy. When the call arrives at the server, the framework extracts the URI from the message, examines the remoting framework tables to locate the reference for the object that matches the URI, and then instantiates the object if necessary, forwarding the method call to the object. If the object is registered as SingleCall, it is destroyed after the method call is completed. A new instance of the object is created for each method called.

But for CAO, the new operator or the CreateInstance methods send a Activation message to the server machine when the client creates the object and a proxy is created on the client side. Constructors with parameters are supported.