HttpRemotingHandlerFactory.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. using System.Web;
  11. using System.IO;
  12. using System.Runtime.Remoting;
  13. using System.Runtime.Remoting.Channels;
  14. namespace System.Runtime.Remoting.Channels.Http
  15. {
  16. public class HttpRemotingHandlerFactory : IHttpHandlerFactory
  17. {
  18. static bool webConfigLoaded = false;
  19. static HttpServerTransportSink transportSink = null;
  20. public HttpRemotingHandlerFactory ()
  21. {
  22. }
  23. public IHttpHandler GetHandler (HttpContext context,
  24. string verb,
  25. string url,
  26. string filePath)
  27. {
  28. if (!webConfigLoaded)
  29. ConfigureHttpChannel (context);
  30. return new HttpRemotingHandler (transportSink);
  31. }
  32. public void ConfigureHttpChannel (HttpContext context)
  33. {
  34. lock (GetType())
  35. {
  36. if (webConfigLoaded) return;
  37. // Look for a channel that wants to receive http request
  38. foreach (IChannel channel in ChannelServices.RegisteredChannels)
  39. {
  40. IChannelReceiverHook chook = channel as IChannelReceiverHook;
  41. if (chook == null) continue;
  42. if (chook.ChannelScheme != "http")
  43. throw new RemotingException ("Only http channels are allowed when hosting remoting objects in a web server");
  44. if (!chook.WantsToListen) continue;
  45. // Register the uri for the channel. The channel uri includes the scheme, the
  46. // host and the application path
  47. string channelUrl = context.Request.Url.GetLeftPart(UriPartial.Authority);
  48. channelUrl += context.Request.ApplicationPath;
  49. chook.AddHookChannelUri (channelUrl);
  50. transportSink = new HttpServerTransportSink (chook.ChannelSinkChain);
  51. }
  52. webConfigLoaded = true;
  53. }
  54. }
  55. public void ReleaseHandler (IHttpHandler handler)
  56. {
  57. }
  58. }
  59. }