RegisterChannel on the client (.NET Remoting)
Hi. I'm working through the .NET Remoting chapter of the book, and I have a question. Any help would be appreciated. The following code (taken from the downloaded source code) is from the HelloClient.cs file (I deleted a few commented lines):
using System;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels.Http;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Activation;
using System.Runtime.Remoting.Lifetime;
namespace Wrox.ProCSharp.Remoting
{
public class HelloClient
{
public static void Main(string[] args)
{
ChannelServices.RegisterChannel(new TcpChannel());
object[] attrs =
{new UrlAttribute("tcp://localhost:8086/Hello") };
Hello obj = (Hello)Activator.CreateInstance(typeof(Hello),
null, attrs);
ILease lease = (ILease)obj.GetLifetimeService();
if (lease != null)
{
Console.WriteLine("Lease Configuration:");
Console.WriteLine("InitialLeaseTime: " +
lease.InitialLeaseTime);
Console.WriteLine("RenewOnCallTime: " +
lease.RenewOnCallTime);
Console.WriteLine("SponsorshipTimeout: " +
lease.SponsorshipTimeout);
Console.WriteLine(lease.CurrentLeaseTime);
}
MySerialized ser = obj.GetMySerialized();
if (!RemotingServices.IsTransparentProxy(ser))
{
Console.WriteLine("ser is not a transparent proxy");
}
ser.Foo();
MyRemote rem = obj.GetMyRemote();
if (RemotingServices.IsTransparentProxy(rem))
{
Console.WriteLine("rem is a transparent proxy");
}
rem.Foo();
System.Console.ReadLine();
}
}
}
I executed the sample and everything worked as expected, the server was active, the remote methods were called. So my question is: what's the need for the following line:
ChannelServices.RegisterChannel(new TcpChannel());
I tried commenting it and everything worked exctly the same way! I see a need for registering a channel for the TCP client but no handle to it seems to be given by the previous code. Can anyone explain this to me?
Thanks in advance,
Miguel Barrosa
|