TCP Remoting Sample 

Download sample

This sample shows how to use the .NET Framework remoting architecture. In addition, it uses XML configuration files to specify available objects and server location information instead of hard-coding them into the binaries or putting the data into the system registry.

Security noteSecurity Note

This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.

To open the sample file in Solution Explorer

  1. Click Download Sample.

    The File Download message box appears.

  2. Click Open, and on the left column of the zip folder window, click Extract all files.

    The Extraction Wizard opens.

  3. Click Next. You can change the directory that the files will be extracted to, and then click Next again.

  4. Make sure that the Show extracted files check box is selected, and click Finish.

  5. Double-click the sample's .sln file.

    The sample solution is displayed in Solution Explorer. You might get a security warning that says the solution location is not trusted. Click OK to continue.

To run this sample

  1. Build the RemoteCustomer project.

  2. Open the RemoteHost project and use F5 to start the RemoteHost application.

  3. Launch another instance of Visual Studio and load the Client project, then add a reference to the compiled RemoteCustomer application (RemoteCustomer.dll).

  4. Use F5 to start the Client application.

  5. To test on two different computers, you will need to make changes to the client's .config file, changing localhost to an IP address or DNS name for the server computer. In addition, you might need to change the server's file if you change the port number. See the comments in both the client's .config file and the host's .config file for examples.


The sample contains three solutions, each with one project:

  • RemoteCustomer: the Server

  • RemoteHost: the Host

  • Client: the Client


The RemoteCustomer is a class library that exposes three creatable types:

  • Customer (client activated)

  • SingleCallCustomer (WellKnown singlecall)

  • SingletonCustomer (WellKnown singleton)

Each class lives in the same namespace, RemotingSample, which is defined in each class source file.


The RemoteHost project contains a Windows Forms application that will read an XML configuration file named Host.exe.config to make available the classes defined in the RemoteCustomer project. For a production application, you might want to host the class library (RemoteCustomer.dll) in a Windows service.


The Client project is a Windows Forms application. It relies upon a configuration file named Client.exe.config to know where to look for the remote objects.

See Also

Community Additions