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...Compile a Client Against an Interface?

This example illustrates how to build a client that does not reference a server object at compile time. The following code example demonstrates the client code.

		
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) {
      TcpChannel chan = new TcpChannel();
      ChannelServices.RegisterChannel(chan);
      IHello obj = (IHello)Activator.GetObject(typeof(RemotingSamples.IHello), "tcp://localhost:8085/SayHello");
      if (obj == null) System.Console.WriteLine("Could not locate server");
      else Console.WriteLine(obj.HelloMethod("Caveman"));
      return 0;
    }
  }
}



C#

The client calls GetObject on an endpoint without knowing what the exact object type is. All it knows is that the object implements IHello.

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




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