Home   |   QuickStart Welcome   |   ASP.NET   |   Web Services   |   How Do I...?   
  |   I want my samples in...      

How Do I...? Common Tasks QuickStart Tutorial

How Do I...Create a Client of a Remote Server?

If you haven't already read the section How Do I Create a Remote Server?, please read this first. The client references the server assembly for metadata, so you have to compile the server before the client. The code for the client is listed below.

using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

namespace RemotingSamples {
    public class Client {
        public static int Main(string [] args) {
            HelloServer obj = (HelloServer)Activator.GetObject(
            if (obj == null) System.Console.WriteLine("Could not locate server");
            else Console.WriteLine(obj.HelloMethod("Caveman"));
            return 0;

When the client starts up, it registers a TCP channel and proceeds to activate the object by calling the GetObject method on the Activator class. One point to be noted is that, for the client to activate the object the dll should be copied from the Server machine to the client machine. The parameters for this call are as follows:

  1. The type of the name of the class you need to activate, RemotingSamples.HelloServer.

  2. Specify the URI of the object you need to activate. For this client the URI is tcp://localhost:8085/SayHello. Note that the URI includes the protocol, machine name, port number, and the endpoint. If the server is deployed on a host named Sunshine, clients can connect to the server by specifying tcp://sunshine:8085/SayHello.

When you run the client, it locates and connects to the server, retrieves a proxy for the remote object, and calls the HelloMethod on the remote object, passing the string "Caveman" as a parameter. The server returns "Hi there Caveman".

NOTE: All TCP channels use binary serialization when transporting local objects to and from a remote object.

VB Hello Client Sample
View Source
[This sample can be found at C:\DevFusion.Data\legacy\quickstart.developerfusion.co.uk\QuickStart\HowTo\Samples\Remoting\Hello\]

Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright � 2004 Microsoft Corporation. All rights reserved.