HttpRemotingHandlerFactory.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. // Read the configuration file
  38. string webconfig = Path.Combine (context.Request.PhysicalApplicationPath, "web.config");
  39. RemotingConfiguration.Configure (webconfig);
  40. // Look for a channel that wants to receive http request
  41. foreach (IChannel channel in ChannelServices.RegisteredChannels)
  42. {
  43. IChannelReceiverHook chook = channel as IChannelReceiverHook;
  44. if (chook == null) continue;
  45. if (chook.ChannelScheme != "http")
  46. throw new RemotingException ("Only http channels are allowed when hosting remoting objects in a web server");
  47. if (!chook.WantsToListen) continue;
  48. // Register the uri for the channel. The channel uri includes the scheme, the
  49. // host and the application path
  50. string channelUrl = context.Request.Url.GetLeftPart(UriPartial.Authority);
  51. channelUrl += context.Request.ApplicationPath;
  52. chook.AddHookChannelUri (channelUrl);
  53. transportSink = new HttpServerTransportSink (chook.ChannelSinkChain);
  54. }
  55. webConfigLoaded = true;
  56. }
  57. }
  58. public void ReleaseHandler (IHttpHandler handler)
  59. {
  60. }
  61. }
  62. }