HelloClient.cs
上传用户:lxycoco
上传日期:2022-07-21
资源大小:38457k
文件大小:2k
- 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());
- // Hello obj = (Hello)Activator.GetObject(typeof(Hello),
- // "tcp://localhost:8086/Hi");
- // if (obj == null)
- // {
- // Console.WriteLine("could not locate server");
- // return;
- // }
- 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();
- }
- }
- }