日期:2014-05-20 浏览次数:21054 次
using System;
namespace Wrox.ProCSharp.Remoting
{
public class Hello: System.MarshalByRefObject
{
public Hello()
{
Console.WriteLine("构造函数启动了!");
}
~Hello()
{
Console.WriteLine("析构函数启动了!");
}
public string Greeting(string name)
{
Console.WriteLine("问候启动了!");
return "你好," + name;
}
}
}
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
namespace Wrox.ProCSharp.Remoting
{
class Program
{
static void Main(string[] args)
{
TcpServerChannel channel = new TcpServerChannel(8086);
ChannelServices.RegisterChannel(channel, false);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(Hello), "Hi", WellKnownObjectMode.SingleCall);
System.Console.WriteLine("press return to exit");
System.Console.ReadLine();
}
}
}
using System;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
namespace Wrox.ProCSharp.Remoting
{
class Program
{
static void Main(string[] args)
{
ChannelServices.RegisterChannel(new TcpClientChannel(), false);
Hello obj = (Hello)Activator.GetObject(typeof(Hello), "tcp://localhost:8086/Hi");
if (obj == null)
{
Console.WriteLine("could not locate server");
return;