18.6 Using Remoting Configuration Files

 <  Day Day Up  >  

You want to use configuration files to define the channel and remote object instead of defining this information in the code.


Technique

Instead of creating channels and registering the remote object in the code, you can replace the entire channel and object registration with a single line of code. The method RemotingConfiguration.Configure reads a configuration file and creates and registers all channels and objects accordingly :

 
 RemotingConfiguration.Configure("6_Server.exe.config"); 

To define the configuration of a well-known object with the HTTP channel, the configuration file for the server is shown in Listing 18.1. The <wellknown> element specifies a well-known object. You can specify the SingleCall or Singleton object type with the mode attribute. The type attribute defines the type and the assembly of the remote object. objectUri specifies the name of the object that the client will use. With the <channels> element, the remoting channels are specified.

Listing 18.1 A Server Configuration File to Define a Well-Known Object with the HTTP Channel
 <?xml version="1.0" encoding="utf-8" ?> <configuration>     <system.runtime.remoting>         <application>             <service>                 <wellknown mode="SingleCall"                        type="_1_RemotingObject.RemoteObject, 1_RemoteObject"                        objectUri="Demo" />             </service>             <channels>                 <channel port="8088" ref="http" />             </channels>         </application>     </system.runtime.remoting> </configuration> 

Listing 18.2 shows the configuration file for the client. With the client, you need only the url and the type attributes with the <wellknown> element. With the client configuration file, you must specify the protocol, server name, port number, and object name with the url . The <channel> configuration of the server defined the port number of the server because the client application must know this port number. With the client application, there is no need to define a fixed port number. If you set the port number to , any free port number is selected automatically.

Listing 18.2 A Client Configuration File to Define a Well-Known Object with the HTTP Channel
 <?xml version="1.0" encoding="utf-8" ?> <configuration>     <system.runtime.remoting>         <application>             <client>                 <wellknown url="http://localhost:8088/Demo"                        type="_1_RemoteObject.RemoteObject, 1_RemoteObject" />             </client>             <channels>                 <channel port="0" ref="http" />             </channels>         </application>     </system.runtime.remoting> </configuration> 

To define client-activated objects, you can specify the <activated> element in the configuration file.

Comments

Using configuration files for .NET Remoting makes it easy to change the configuration without the need to change the code.

 <  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