HelloClient.cs
上传用户:lxycoco
上传日期:2022-07-21
资源大小:38457k
文件大小:2k
源码类别:

C#编程

开发平台:

Others

  1. using System;
  2. using System.Runtime.Remoting.Channels;
  3. using System.Runtime.Remoting.Channels.Tcp;
  4. using System.Runtime.Remoting.Channels.Http;
  5. using System.Runtime.Remoting;
  6. using System.Runtime.Remoting.Activation;
  7. using System.Runtime.Remoting.Lifetime;
  8. namespace Wrox.ProCSharp.Remoting
  9. {
  10. public class HelloClient
  11. {
  12. public static void Main(string[] args)
  13. {
  14. ChannelServices.RegisterChannel(new TcpChannel());
  15. // Hello obj = (Hello)Activator.GetObject(typeof(Hello),
  16. // "tcp://localhost:8086/Hi");
  17. // if (obj == null)
  18. // {
  19. // Console.WriteLine("could not locate server");
  20. // return;
  21. // }
  22. object[] attrs = {new UrlAttribute("tcp://localhost:8086/Hello") };
  23. Hello obj = (Hello)Activator.CreateInstance(typeof(Hello), null, attrs);
  24. ILease lease = (ILease)obj.GetLifetimeService();
  25. if (lease != null)
  26. {
  27. Console.WriteLine("Lease Configuration:");
  28. Console.WriteLine("InitialLeaseTime: " +
  29. lease.InitialLeaseTime);
  30. Console.WriteLine("RenewOnCallTime: " +
  31. lease.RenewOnCallTime);
  32. Console.WriteLine("SponsorshipTimeout: " +
  33. lease.SponsorshipTimeout);
  34. Console.WriteLine(lease.CurrentLeaseTime);
  35. }
  36. MySerialized ser = obj.GetMySerialized();
  37. if (!RemotingServices.IsTransparentProxy(ser))
  38. {
  39. Console.WriteLine("ser is not a transparent proxy");
  40. }
  41. ser.Foo();
  42. MyRemote rem = obj.GetMyRemote();
  43. if (RemotingServices.IsTransparentProxy(rem))
  44. {
  45. Console.WriteLine("rem is a transparent proxy");
  46. }
  47. rem.Foo();
  48. }
  49. }
  50. }