A Simple Introduction to .NET Remoting

Host Application

To enable client applications to use our remotable object we need to build a Host application which will listen for object requests. This application will register a channel and register our remotable object with the .NET remoting system to use that channel to listen for requests.

.NET includes two default channels:

  • HttpChannel (using SOAP formatting)
  • TcpChannel (using binary formatting)

NOTE: Because remote configuration is done on a per-application-domain basis, the application domain must be running to listen for requests.

Create a console application project called "RemotingHost". Add a reference to our RemotableType and add the following class.

using System;
using System.Runtime.Remoting;
public class RemotingHost
  public static void Main(){
    RemotingConfiguration.Configure("RemotingHost.exe.config");
    Console.WriteLine("Host Running. Listening for Object Requests.");
    Console.ReadLine();
  }
}

You can configure .NET remoting through code or via a configuration file. In this example we are using app.config so add a app.config file to you project and add the following entries:

<configuration>
  <system.runtime.remoting>
      <application>
        <service>
            <wellknown
              mode="Singleton"
              type="RemotableType, RemotableType"
              objectUri="RemotableType.rem"
            />
        </service>
        <channels>
            <channel ref="http" port="8989"/>
        </channels>
      </application>
  </system.runtime.remoting>
</configuration>

Our Host class loads the config information from the app.config file using the RemotingConfiguration.Configure() method.

You might also like...

Comments

About the author

Lee Gunn - .NET C# Scotland United Kingdom

Lee Gunn is a freelance Microsoft Certified Developer based in Glasgow, Scotland. Specialising in quality driven Internet solutions, largely built around Microsoft’s .NET platform.

Skills ...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“In theory, theory and practice are the same. In practice, they're not.”