C# Remote Listener Object

We already created a Remote Type Object C# Remotable Object in the previous section. We have to create a listener Object for enable Objects in other application domains to create instances of this object ( RemoteTime ) Remotely. When creating a listener Object we have to choose and register a channel for handle the networking protocol and serialization formats and register the Type with the .NET Remoting System , so that it can use the channel to listen for requests for the Type. C# Remote Channels are Objects that responsible of handling the network protocols and serialization formats.

In the following C# source code we are creating a listener application TimeListener.cs . It will act as a listener Object for the Remote Type RemoteTime. The Listener class TimeListener must be able to find the TimeListener.exe.config file to load the configuration for the RemotableType class.

Full Source C#
using System; using System.Runtime.Remoting; public class TimeListener { public static void Main() { RemotingConfiguration.Configure("TimeListener.exe.config"); Console.WriteLine("Listening for requests from the Client! Press Enter to exit..."); Console.ReadLine(); } }

Copy and paste the above C# source code into a file and save it as TimeListener.cs .

We have to create additional configuration file to provide the communication information to the listener Object. The configuration file is an XML structured file. We can specify the Activation Mode , the Remote Type , Channel , port for communication etc. through the configuration file .


Click here to download TimeListener.exe.config

Compile the class file TimeListener.cs using the command-line tools that ship with the Visual Studio SDK .

At the command prompt type the following command:

csc /r:RemoteTime.dll TimeListener.cs

After you compile the TimeListener.cs , you will get a file called TimeListener.exe in the directory where your compiler resides.

If your file TimeListener.cs and RemoteTime.dll is residing in c:\src then you should type command like the following :

csc /r:c:\src\RemoteTime.dll c:\src\TimeListener.cs