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

C#编程

开发平台:

Others

  1. using System;
  2. using System.Runtime.Remoting;
  3. using System.Runtime.Remoting.Channels;
  4. using System.Runtime.Remoting.Channels.Tcp;
  5. using System.Runtime.Remoting.Channels.Http;
  6. using System.Collections;
  7. namespace Wrox.ProCSharp.Remoting
  8. {
  9. public class HelloServer
  10. {
  11. protected static void ShowChannelProperties(IChannelReceiver channel)
  12. {
  13. Console.WriteLine("Name: " + channel.ChannelName);
  14. Console.WriteLine("Priority: " + channel.ChannelPriority);
  15. if (channel is HttpChannel)
  16. {
  17. HttpChannel httpChannel = channel as HttpChannel;
  18. Console.WriteLine("Scheme: " + httpChannel.ChannelScheme);
  19. }
  20. ChannelDataStore data = (ChannelDataStore)channel.ChannelData;
  21. foreach (string uri in data.ChannelUris)
  22. {
  23. Console.WriteLine("URI: " + uri);
  24. }
  25. Console.WriteLine();
  26. }
  27. public static void Main(string[] args)
  28. {
  29. // IDictionary properties = new Hashtable();
  30. // properties["name"] = "TCP Channel";
  31. //// properties["priority"] = "20";
  32. // properties["port"] = "8086";
  33. // BinaryServerFormatterSinkProvider sinkProvider = 
  34. // new BinaryServerFormatterSinkProvider();
  35. //// SoapServerFormatterSinkProvider sinkProvider = 
  36. //// new SoapServerFormatterSinkProvider();
  37. // sinkProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
  38. // TcpServerChannel tcpChannel = 
  39. // new TcpServerChannel(properties, sinkProvider);
  40. TcpServerChannel tcpChannel = new TcpServerChannel(8086);
  41. ShowChannelProperties(tcpChannel);
  42. HttpServerChannel httpChannel = new HttpServerChannel(8085);
  43. ShowChannelProperties(httpChannel);
  44. ChannelServices.RegisterChannel(tcpChannel);
  45. ChannelServices.RegisterChannel(httpChannel);
  46. // RemotingConfiguration.RegisterWellKnownServiceType(
  47. // typeof(Hello), "Hi",
  48. // WellKnownObjectMode.SingleCall);
  49. RemotingConfiguration.ApplicationName = "Hello";
  50. RemotingConfiguration.RegisterActivatedServiceType(
  51. typeof(Hello));
  52. System.Console.WriteLine("press return to exit");
  53. System.Console.ReadLine();
  54. }
  55. }
  56. }