1 创建服务器通道
并在.Net Remotion运行时注册改通道
注册一个知名对象
1 TcpServerChannel channel = new TcpServerChannel(9000); 2 3 ChannelServices.RegisterChannel(channel, false); 4 5 WellKnownServiceTypeEntry remObj = new WellKnownServiceTypeEntry( 6 typeof(MyRemoteObject), "MyRemoteObject", WellKnownObjectMode.SingleCall); 8 9 RemotingConfiguration.RegisterWellKnownServiceType(remObj); 10 11 Console.ReadKey();
2 客户端端
1 TcpClientChannel channel = new TcpClientChannel(); 2 ChannelServices.RegisterChannel(channel,false); 3 //方式 1 4 //WellKnownClientTypeEntry entry = new WellKnownClientTypeEntry(typeof(MyRemoteObject), 5 // "tcp://localhost:9000/MyRemoteObject"); 6 //RemotingConfiguration.RegisterWellKnownClientType(entry); 7 //MyRemoteObject obj = new MyRemoteObject(); 8 //方式 2 9 MyRemoteObject obj = (MyRemoteObject)Activator.GetObject(typeof(MyRemoteObject), 10 "tcp://localhost:9000/MyRemoteObject"); 11 12 Console.WriteLine(obj.Hello());
时间: 2024-10-25 03:07:35