How to: Build a Client Application

This topic is specific to a legacy technology that is retained for backward compatibility with existing applications and is not recommended for new development. Distributed applications should now be developed using the  Windows Communication Foundation (WCF).

To build a client of the remote type defined in How to: Build a Remotable Type and hosted by the application created in How to: Build a Hosting Application, your application must register itself as a client for that remote object and then invoke it as though it were within the client's application domain. The .NET remoting system intercepts your client calls, forwards them to the remote object, and returns the results to your client. The following procedure describes how to build a basic remoting client.

See How to: Compile and Run a Basic Remoting Application for complete instructions on how to build and run this sample.

To build a basic remoting client

  1. Continuing on from How to: Build a Hosting Application, create a new directory under remoting called client. Create a configuration file for the client application as shown in the following code and save the file in the remoting\client directory. The file name should follow the pattern of app-name.exe.config. In this case, it is called client.exe.config. The following configuration file tells the remoting system that the type information for the RemotableType remote object can be found in the RemotableType assembly and the object is located at http://localhost:8989/RemotableType.rem.

                   type="RemotableType, RemotableType"

    For details about the URL attribute in this configuration file, see Activation URLs. If you want to run this application over a network, you must replace localhost in the client configuration with the name of the remote computer.

    Although there are only a few settings in the preceding configuration file, most of the problems using .NET remoting occur because some of these settings are either incorrect or do not match the configuration settings for client applications. It is easy to mistype a name, forget a port, or neglect an attribute. If you are having problems with your remoting application, check your configuration settings first.

  2. Create a new source file in the language of your choice. In the main method, call RemotingConfiguration.Configure passing in the name of the client configuration file (client.exe.config). Next, instantiate an instance of RemotableType and call its SayHello method. Save the client application as Client.cs or Client.vb in the remoting\client directory.

    The client application should not be saved in the same directory as that of your Listener.exe application. If it is, you cannot be certain that you are receiving and making use of a remote reference, because assembly and type resolution can occur when applications are in the same directory.

       public static void Main(){
          RemotableType remoteObject = new RemotableType();
  3. Copy the RemotableType.dll assembly from remoting\Type into remoting\client.

    A common question at this point is "How do I know that the remote object gets called if I am copying the assembly to the client?" This is exactly why we added the call to Console.WriteLine in the RemotableType.SayHello() method. If the remote object is being called the WriteLine occurs in the Listener process, if not the WriteLine occurs in the client process.

  4. Compile client application by typing the following command in the remoting\client directory:

    csc /noconfig /r:RemotableType.dll Client.cs
  5. Open up two command prompts. In one, go to the remoting\listener directory and run listener.exe. In the other, go to the remoting\client directory and run client.exe. The client command-prompt should look like this:

    Hello, world 
  6. The listener command-prompt should look like this:

    Listening for requests. Press Enter to exit...
    RemotableType.SayHello() was called!
  7. You can see by the output of the listener that it received a call to RemotableType.SayHello().


// Client.cs 
using System;
using System.Runtime.Remoting;

public class Client{

   public static void Main(){
      RemotableType remoteObject = new RemotableType();

See Also

Copyright © 2007 by Microsoft Corporation. All rights reserved.