HttpChannel.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. //
  17. // Permission is hereby granted, free of charge, to any person obtaining
  18. // a copy of this software and associated documentation files (the
  19. // "Software"), to deal in the Software without restriction, including
  20. // without limitation the rights to use, copy, modify, merge, publish,
  21. // distribute, sublicense, and/or sell copies of the Software, and to
  22. // permit persons to whom the Software is furnished to do so, subject to
  23. // the following conditions:
  24. //
  25. // The above copyright notice and this permission notice shall be
  26. // included in all copies or substantial portions of the Software.
  27. //
  28. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  29. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  30. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  31. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  32. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  33. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  34. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  35. //
  36. using System;
  37. using System.Collections;
  38. using System.Runtime.Remoting.Messaging;
  39. namespace System.Runtime.Remoting.Channels.Http
  40. {
  41. public class HttpChannel: BaseChannelWithProperties, IChannelReceiver,
  42. IChannelSender, IChannel, IChannelReceiverHook
  43. {
  44. private HttpServerChannel serverChannel;
  45. private HttpClientChannel clientChannel;
  46. private string channelName = "http";
  47. private int channelPriority = 1;
  48. private AggregateDictionary properties;
  49. public HttpChannel()
  50. {
  51. SetupChannel (new Hashtable(), null, null);
  52. }
  53. public HttpChannel (int port)
  54. {
  55. Hashtable prop = new Hashtable();
  56. prop["port"] = port;
  57. SetupChannel(prop,null,null);
  58. }
  59. public HttpChannel (IDictionary properties,IClientChannelSinkProvider clientSinkProvider,IServerChannelSinkProvider serverSinkProvider)
  60. {
  61. SetupChannel (properties,clientSinkProvider,serverSinkProvider);
  62. }
  63. private void SetupChannel (IDictionary properties, IClientChannelSinkProvider clientSinkProvider, IServerChannelSinkProvider serverSinkProvider)
  64. {
  65. clientChannel = new HttpClientChannel (properties, clientSinkProvider);
  66. serverChannel = new HttpServerChannel (properties, serverSinkProvider);
  67. object val = properties ["name"];
  68. if (val != null) channelName = val as string;
  69. val = properties ["priority"];
  70. if (val != null) channelPriority = Convert.ToInt32 (val);
  71. this.properties = new AggregateDictionary (new IDictionary[] {clientChannel, serverChannel});
  72. }
  73. //IChannel Members
  74. public String ChannelName
  75. {
  76. get { return channelName; }
  77. }
  78. public int ChannelPriority
  79. {
  80. get { return channelPriority; }
  81. }
  82. public String Parse(String url, out String objectURI)
  83. {
  84. return HttpHelper.Parse(url, out objectURI);
  85. }
  86. //IChannelSender Members
  87. public IMessageSink CreateMessageSink(String url, Object remoteChannelData, out String objectURI)
  88. {
  89. return clientChannel.CreateMessageSink(url, remoteChannelData, out objectURI);
  90. }
  91. //IChannelReciever Members
  92. public String[] GetUrlsForUri(String objectURI)
  93. {
  94. return serverChannel.GetUrlsForUri(objectURI);
  95. }
  96. public void StartListening(Object data)
  97. {
  98. serverChannel.StartListening(data);
  99. }
  100. public void StopListening(Object data)
  101. {
  102. serverChannel.StopListening(data);
  103. }
  104. public Object ChannelData
  105. {
  106. get { return serverChannel.ChannelData; }
  107. }
  108. public String ChannelScheme
  109. {
  110. get { return "http"; }
  111. }
  112. public bool WantsToListen
  113. {
  114. get { return serverChannel.WantsToListen; }
  115. set { serverChannel.WantsToListen = value; }
  116. }
  117. public IServerChannelSink ChannelSinkChain
  118. {
  119. get { return serverChannel.ChannelSinkChain; }
  120. }
  121. public void AddHookChannelUri (String channelUri)
  122. {
  123. serverChannel.AddHookChannelUri (channelUri);
  124. }
  125. public override object this [object key]
  126. {
  127. get { return properties[key]; }
  128. set { properties[key] = value; }
  129. }
  130. public override ICollection Keys
  131. {
  132. get { return properties.Keys; }
  133. }
  134. public override IDictionary Properties
  135. {
  136. get { return properties; }
  137. }
  138. }
  139. }