18.3 Calling Remote Objects from Client Applications

 <  Day Day Up  >  

After you create a remoting object and a server, you want to use a client application to call methods of the remote object.


Technique

Similar to the server, with the client you also have to register a channel using ChannelServices.RegisterChannel . The channel to be registered must use the same protocol that is offered by a server channel:

 
 ChannelServices.RegisterChannel(new TcpChannel()); 

To get an instance of a proxy that is needed to invoke methods in the remote object, you can use the Activator class. Activator.GetObject returns a proxy to a well-known remote object. For the proxy, you need the type of the remote object class, here RemoteObject , and the URL to the remote object. The URL consists of the protocol ( tcp ), the server and port number, and the name of the remote object ( Demo ):

 
 _1_RemoteObject.RemoteObject obj =          (_1_RemoteObject.RemoteObject)Activator.GetObject(                  typeof(_1_RemoteObject.RemoteObject),                  "tcp://localhost:8088/Demo"); obj.Method(); 

Instead of using the Activator class, you can also register the remoting object with the runtime, as you did on the server side earlier. The difference with the server side is that with the client you must call the method RegisterWellKnownClientType . After the remote object class is registered, you can use the new operator to instantiate the remote object:

 
 RemotingConfiguration.RegisterWellKnownClientType(typeof(RemoteObject),                                                   "tcp://localhost:8088/Demo"); RemoteObject obj = new RemoteObject(); obj.Method(); 
 <  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