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 Microsoft.Samples.Remoting.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.
C# Interface
[This sample can be found at M:\web\users\Sites\AspnetQuickStart\v2.0\QuickStart\HowTo\Samples\Remoting\interface\
To build this sample, open the SDK command prompt and navigate to the above path. Build the sample using the build tool msbuild
passing the solution file as the first parameter: msbuild mySample.sln. The compiled executable will be found in the sub directory \bin
directory.]
Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright � 2005 Microsoft Corporation. All rights reserved.
|