Method 2: (Using a configuration file on the client to register the channel and specify the object's URN) Creating and registering the channel explicitly and then using Acivator.GetObject is just one way of invoking the remote object. You can also specify the channel and the URI endpoint of the remote object through a configuration file , and just instantiate the Diner object using new . The client application will use the information in the loaded configuration file to register the channel and activate the object at the URI endpoint specified.
The general format of the client configuration file is as follows:
Name#Name of the Application Assembly#[AssemblyName]#[RemoteApplicationName] #[FullTypeName]=[ObjectURI] RemoteApplication#[RemoteApplicationName] #[RemoteApplicationURI] Channel#[ChannelAssemblyName]#[ChannelFullTypeName]#[Name=Value;Name=Value]
So based on the above format, here's how your configuration file ( MyDinerClient.cfg ) would look like:
To load this configuration file, we have to use the RemotingServices.ConfigureRemoting method and pass it the name of the client configuration file to use. The information in the configuration file is used to register the channel and use the specified remote URI endpoint to activate the object. You must load the configuration file only once, typically when your application starts up. Shown below is the global.asax file for an ASP.NET consumer application that loads the configuration file.
<%@ Import Namespace="System.Runtime.Remoting" %> <script runat="server" language="vb"> Sub Application_OnStart() RemotingServices.ConfigureRemoting(HttpContext.Current. Server.MapPath("MyDinerClient.cfg")) End Sub </script>
So now, since we have all the details specified in the configuration file, we do not have to explicitly register the channel or provide details about the object's URN endpoint in our code. You would simply have to create the object using new and then call its methods as shown below:
// Create an instance of the remote object Diner dinerObj = new Diner();
// Get Today's Menu from the remote Pizza Service if(dinerObj != null) m_listPizza = dinerObj.getPizzaMenu();
If there's an inkling of doubt whether your ASP.NET page is accessing the locally deployed assembly instead of the remote one, simply shut down the remote server or rename the assembly on the remote server and you will see that the client will choke.