2 // System.Runtime.Remoting.Channels.Http.HttpRemotingHandlerFactory
5 // Martin Willemoes Hansen (mwh@sysrq.dk)
6 // Lluis Sanchez Gual (lluis@ximian.com)
8 // (C) 2003 Martin Willemoes Hansen
13 using System.Runtime.Remoting;
14 using System.Runtime.Remoting.Channels;
16 namespace System.Runtime.Remoting.Channels.Http
18 public class HttpRemotingHandlerFactory : IHttpHandlerFactory
20 static bool webConfigLoaded = false;
21 static HttpServerTransportSink transportSink = null;
23 public HttpRemotingHandlerFactory ()
27 public IHttpHandler GetHandler (HttpContext context,
33 ConfigureHttpChannel (context);
35 return new HttpRemotingHandler (transportSink);
38 void ConfigureHttpChannel (HttpContext context)
42 if (webConfigLoaded) return;
44 // Look for a channel that wants to receive http request
46 foreach (IChannel channel in ChannelServices.RegisteredChannels)
48 IChannelReceiverHook chook = channel as IChannelReceiverHook;
49 if (chook == null) continue;
51 if (chook.ChannelScheme != "http")
52 throw new RemotingException ("Only http channels are allowed when hosting remoting objects in a web server");
54 if (!chook.WantsToListen) continue;
56 // Register the uri for the channel. The channel uri includes the scheme, the
57 // host and the application path
59 string channelUrl = context.Request.Url.GetLeftPart(UriPartial.Authority);
60 channelUrl += context.Request.ApplicationPath;
61 chook.AddHookChannelUri (channelUrl);
63 transportSink = new HttpServerTransportSink (chook.ChannelSinkChain, null);
65 webConfigLoaded = true;
69 public void ReleaseHandler (IHttpHandler handler)