18.4 Performing Client-Side Activation of Remotable Objects

 <  Day Day Up  >  

You want to use stateful remoting objects with .NET Remoting.


Technique

To keep state in the remote object, it is just necessary to register the remote object as a client-activated object with the method RegisterActivatedServiceType after the channel is registered:

 
 RemotingConfiguration.RegisterActivatedServiceType(         typeof(_1_RemoteObject.RemoteObject)); 

With the client application, you can use the CreateInstance method of the Activator class with client-activated objects.

With the client application, you can use either the Activator class or the class RemotingConfiguration to configure the client-activated object type. With the Activator class, you use the method GetObject with well-known objects, but with client-activated objects, you need the method CreateInstance . With this method, you can pass arguments to a nondefault constructor ( null in this example) and attributes. With the attributes, you have to set the URL to the remote object:

 
 object[] attrs = { new UrlAttribute("tcp://localhost:8088/Demo") }; _1_RemoteObject.RemoteObject obj =         (_1_RemoteObject.RemoteObject)Activator.CreateInstance(                 typeof(_1_RemoteObject.RemoteObject), null, attrs); 

A second way to instantiate client-activated objects is to use the RemotingConfiguration class with the method RegisterActivatedClientType . This way, you can use the new operator to instantiate the remote object, as discussed before:

 
 RemotingConfiguration.RegisterActivatedClientType(         typeof(_1_RemoteObject.RemoteObject),         "tcp://localhost:8088/Demo"); 

Comments

Using stateless objects is the preferred programming model with distributed solutions. With stateful objects, the server has allocated resources for a client.

With stateful objects, be aware that the objects are destroyed on the server after a timeout of a leasing time. The leasing mechanism is discussed in Recipe 18.9, "Controlling Lifetime Leases."

 <  Day Day Up  >  


Microsoft Visual C# .Net 2003
Microsoft Visual C *. NET 2003 development skills Daquan
ISBN: 7508427505
EAN: 2147483647
Year: 2003
Pages: 440

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net