HttpChannel.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. //
  2. // System.Runtime.Remoting.Channels.Http.HttpChannel
  3. //
  4. // Summary: Implements a wrapper class for HTTP client and server channels.
  5. //
  6. // Classes: public HttpChannel
  7. //
  8. // Authors:
  9. // Martin Willemoes Hansen ([email protected])
  10. // Ahmad Tantawy ([email protected])
  11. // Ahmad Kadry ([email protected])
  12. // Hussein Mehanna ([email protected])
  13. //
  14. // (C) 2003 Martin Willemoes Hansen
  15. //
  16. using System;
  17. using System.Collections;
  18. using System.Runtime.Remoting.Messaging;
  19. namespace System.Runtime.Remoting.Channels.Http
  20. {
  21. public class HttpChannel: BaseChannelWithProperties, IChannelReceiver,
  22. IChannelSender, IChannel, IChannelReceiverHook
  23. {
  24. private HttpServerChannel serverChannel;
  25. private HttpClientChannel clientChannel;
  26. private string channelName = "http";
  27. private int channelPriority = 1;
  28. private AggregateDictionary properties;
  29. public HttpChannel()
  30. {
  31. SetupChannel (new Hashtable(), null, null);
  32. }
  33. public HttpChannel (int port)
  34. {
  35. Hashtable prop = new Hashtable();
  36. prop["port"] = port;
  37. SetupChannel(prop,null,null);
  38. }
  39. public HttpChannel (IDictionary properties,IClientChannelSinkProvider clientSinkProvider,IServerChannelSinkProvider serverSinkProvider)
  40. {
  41. SetupChannel (properties,clientSinkProvider,serverSinkProvider);
  42. }
  43. private void SetupChannel (IDictionary properties, IClientChannelSinkProvider clientSinkProvider, IServerChannelSinkProvider serverSinkProvider)
  44. {
  45. clientChannel = new HttpClientChannel (properties, clientSinkProvider);
  46. serverChannel = new HttpServerChannel (properties, serverSinkProvider);
  47. object val = properties ["name"];
  48. if (val != null) channelName = val as string;
  49. val = properties ["priority"];
  50. if (val != null) channelPriority = Convert.ToInt32 (val);
  51. this.properties = new AggregateDictionary (new IDictionary[] {clientChannel, serverChannel});
  52. }
  53. //IChannel Members
  54. public String ChannelName
  55. {
  56. get { return channelName; }
  57. }
  58. public int ChannelPriority
  59. {
  60. get { return channelPriority; }
  61. }
  62. public String Parse(String url, out String objectURI)
  63. {
  64. return HttpHelper.Parse(url, out objectURI);
  65. }
  66. //IChannelSender Members
  67. public IMessageSink CreateMessageSink(String url, Object remoteChannelData, out String objectURI)
  68. {
  69. return clientChannel.CreateMessageSink(url, remoteChannelData, out objectURI);
  70. }
  71. //IChannelReciever Members
  72. public String[] GetUrlsForUri(String objectURI)
  73. {
  74. return serverChannel.GetUrlsForUri(objectURI);
  75. }
  76. public void StartListening(Object data)
  77. {
  78. serverChannel.StartListening(data);
  79. }
  80. public void StopListening(Object data)
  81. {
  82. serverChannel.StopListening(data);
  83. }
  84. public Object ChannelData
  85. {
  86. get { return serverChannel.ChannelData; }
  87. }
  88. public String ChannelScheme
  89. {
  90. get { return "http"; }
  91. }
  92. public bool WantsToListen
  93. {
  94. get { return serverChannel.WantsToListen; }
  95. set { serverChannel.WantsToListen = value; }
  96. }
  97. public IServerChannelSink ChannelSinkChain
  98. {
  99. get { return serverChannel.ChannelSinkChain; }
  100. }
  101. public void AddHookChannelUri (String channelUri)
  102. {
  103. serverChannel.AddHookChannelUri (channelUri);
  104. }
  105. public override object this [object key]
  106. {
  107. get { return properties[key]; }
  108. set { properties[key] = value; }
  109. }
  110. public override ICollection Keys
  111. {
  112. get { return properties.Keys; }
  113. }
  114. public override IDictionary Properties
  115. {
  116. get { return properties; }
  117. }
  118. }
  119. }