HttpRemotingHandlerFactory.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //
  2. // System.Runtime.Remoting.Channels.Http.HttpRemotingHandlerFactory
  3. //
  4. // Authors:
  5. // Martin Willemoes Hansen ([email protected])
  6. // Lluis Sanchez Gual ([email protected])
  7. //
  8. // (C) 2003 Martin Willemoes Hansen
  9. //
  10. //
  11. // Permission is hereby granted, free of charge, to any person obtaining
  12. // a copy of this software and associated documentation files (the
  13. // "Software"), to deal in the Software without restriction, including
  14. // without limitation the rights to use, copy, modify, merge, publish,
  15. // distribute, sublicense, and/or sell copies of the Software, and to
  16. // permit persons to whom the Software is furnished to do so, subject to
  17. // the following conditions:
  18. //
  19. // The above copyright notice and this permission notice shall be
  20. // included in all copies or substantial portions of the Software.
  21. //
  22. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. //
  30. using System.Web;
  31. using System.IO;
  32. using System.Runtime.Remoting;
  33. using System.Runtime.Remoting.Channels;
  34. namespace System.Runtime.Remoting.Channels.Http
  35. {
  36. public class HttpRemotingHandlerFactory : IHttpHandlerFactory
  37. {
  38. static bool webConfigLoaded = false;
  39. static HttpServerTransportSink transportSink = null;
  40. public HttpRemotingHandlerFactory ()
  41. {
  42. }
  43. public IHttpHandler GetHandler (HttpContext context,
  44. string verb,
  45. string url,
  46. string filePath)
  47. {
  48. if (!webConfigLoaded)
  49. ConfigureHttpChannel (context);
  50. return new HttpRemotingHandler (transportSink);
  51. }
  52. void ConfigureHttpChannel (HttpContext context)
  53. {
  54. lock (GetType())
  55. {
  56. if (webConfigLoaded) return;
  57. // Look for a channel that wants to receive http request
  58. foreach (IChannel channel in ChannelServices.RegisteredChannels)
  59. {
  60. IChannelReceiverHook chook = channel as IChannelReceiverHook;
  61. if (chook == null) continue;
  62. if (chook.ChannelScheme != "http")
  63. throw new RemotingException ("Only http channels are allowed when hosting remoting objects in a web server");
  64. if (!chook.WantsToListen) continue;
  65. // Register the uri for the channel. The channel uri includes the scheme, the
  66. // host and the application path
  67. string channelUrl = context.Request.Url.GetLeftPart(UriPartial.Authority);
  68. channelUrl += context.Request.ApplicationPath;
  69. chook.AddHookChannelUri (channelUrl);
  70. transportSink = new HttpServerTransportSink (chook.ChannelSinkChain, null);
  71. }
  72. webConfigLoaded = true;
  73. }
  74. }
  75. public void ReleaseHandler (IHttpHandler handler)
  76. {
  77. }
  78. }
  79. }