void ConfigureHttpChannel(HttpContext context) { lock (GetType()) { if (webConfigLoaded) { return; } string appConfig = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; if (File.Exists(appConfig)) { RemotingConfiguration.Configure(appConfig); } // Look for a channel that wants to receive http request IChannelReceiverHook chook = null; foreach (IChannel channel in ChannelServices.RegisteredChannels) { chook = channel as IChannelReceiverHook; if (chook == null) { continue; } if (chook.ChannelScheme != "http") { throw new RemotingException("Only http channels are allowed when hosting remoting objects in a web server"); } if (!chook.WantsToListen) { chook = null; continue; } //found chook break; } if (chook == null) { HttpChannel chan = new HttpChannel(); ChannelServices.RegisterChannel(chan); chook = chan; } // Register the uri for the channel. The channel uri includes the scheme, the // host and the application path string channelUrl = context.Request.Url.GetLeftPart(UriPartial.Authority); channelUrl += context.Request.ApplicationPath; chook.AddHookChannelUri(channelUrl); transportSink = new HttpServerTransportSink(chook.ChannelSinkChain); webConfigLoaded = true; } }
// // Internal // // Transform the ASP+ Request and Response Structures in // Channel Structures: // ** Request.ServerVariables // ** Request.InputStream // ** Response.Headers // // This is needed to reduce the between dependency COR Channels // and ASP+ // private void InternalProcessRequest(HttpContext context) { try { HttpRequest httpRequest = context.Request; // check if have previously loaded configuration if (!bLoadedConfiguration) { // locking a random static variable, so we can lock the class lock (HttpRemotingHandler.ApplicationConfigurationFile) { if (!bLoadedConfiguration) { // Initialize IIS information IisHelper.Initialize(); // set application name if (RemotingConfiguration.ApplicationName == null) { RemotingConfiguration.ApplicationName = httpRequest.ApplicationPath; } String filename = String.Concat(httpRequest.PhysicalApplicationPath, ApplicationConfigurationFile); if (File.Exists(filename)) { try { RemotingConfiguration.Configure(filename, false /*enableSecurity*/); } catch (Exception e) { s_fatalException = e; WriteException(context, e); return; } } try { // do a search for a registered channel that wants to listen IChannelReceiverHook httpChannel = null; IChannel[] channels = ChannelServices.RegisteredChannels; foreach (IChannel channel in channels) { IChannelReceiverHook hook = channel as IChannelReceiverHook; if (hook != null) { if (String.Compare(hook.ChannelScheme, "http", StringComparison.OrdinalIgnoreCase) == 0) { if (hook.WantsToListen) { httpChannel = hook; break; } } } } if (httpChannel == null) { // No http channel that was listening found. // Create a new channel. HttpChannel newHttpChannel = new HttpChannel(); ChannelServices.RegisterChannel(newHttpChannel, false /*enableSecurity*/); httpChannel = newHttpChannel; } String scheme = null; if (IisHelper.IsSslRequired) { scheme = "https"; } else { scheme = "http"; } String hookChannelUri = scheme + "://" + CoreChannel.GetMachineIp(); int port = context.Request.Url.Port; String restOfUri = ":" + port + "/" + RemotingConfiguration.ApplicationName; hookChannelUri += restOfUri; // add hook uri for this channel httpChannel.AddHookChannelUri(hookChannelUri); // If it uses ChannelDataStore, re-retrieve updated url in case it was updated. ChannelDataStore cds = ((IChannelReceiver)httpChannel).ChannelData as ChannelDataStore; if (cds != null) { hookChannelUri = cds.ChannelUris[0]; } IisHelper.ApplicationUrl = hookChannelUri; // This is a hack to refresh the channel data. // In V-Next, we will add a ChannelServices.RefreshChannelData() api. ChannelServices.UnregisterChannel(null); s_transportSink = new HttpHandlerTransportSink(httpChannel.ChannelSinkChain); } catch (Exception e) { s_fatalException = e; WriteException(context, e); return; } bLoadedConfiguration = true; } } } if (s_fatalException == null) { if (!CanServiceRequest(context)) { WriteException(context, new RemotingException(CoreChannel.GetResourceString("Remoting_ChnlSink_UriNotPublished"))); } else { s_transportSink.HandleRequest(context); } } else { WriteException(context, s_fatalException); } } catch (Exception e) { WriteException(context, e); } } // InternalProcessRequest
private void InternalProcessRequest(HttpContext context) { try { HttpRequest request = context.Request; if (!bLoadedConfiguration) { lock (ApplicationConfigurationFile) { if (!bLoadedConfiguration) { IisHelper.Initialize(); if (RemotingConfiguration.ApplicationName == null) { RemotingConfiguration.ApplicationName = request.ApplicationPath; } string path = request.PhysicalApplicationPath + ApplicationConfigurationFile; if (File.Exists(path)) { try { RemotingConfiguration.Configure(path, false); } catch (Exception exception) { s_fatalException = exception; this.WriteException(context, exception); return; } } try { IChannelReceiverHook hook = null; foreach (IChannel channel in ChannelServices.RegisteredChannels) { IChannelReceiverHook hook2 = channel as IChannelReceiverHook; if (((hook2 != null) && (string.Compare(hook2.ChannelScheme, "http", StringComparison.OrdinalIgnoreCase) == 0)) && hook2.WantsToListen) { hook = hook2; break; } } if (hook == null) { HttpChannel chnl = new HttpChannel(); ChannelServices.RegisterChannel(chnl, false); hook = chnl; } string str2 = null; if (IisHelper.IsSslRequired) { str2 = "https"; } else { str2 = "http"; } string channelUri = str2 + "://" + CoreChannel.GetMachineIp(); int port = context.Request.Url.Port; string str4 = string.Concat(new object[] { ":", port, "/", RemotingConfiguration.ApplicationName }); channelUri = channelUri + str4; hook.AddHookChannelUri(channelUri); ChannelDataStore channelData = ((IChannelReceiver)hook).ChannelData as ChannelDataStore; if (channelData != null) { channelUri = channelData.ChannelUris[0]; } IisHelper.ApplicationUrl = channelUri; ChannelServices.UnregisterChannel(null); s_transportSink = new HttpHandlerTransportSink(hook.ChannelSinkChain); } catch (Exception exception2) { s_fatalException = exception2; this.WriteException(context, exception2); return; } bLoadedConfiguration = true; } } } if (s_fatalException == null) { if (!this.CanServiceRequest(context)) { this.WriteException(context, new RemotingException(CoreChannel.GetResourceString("Remoting_ChnlSink_UriNotPublished"))); } else { s_transportSink.HandleRequest(context); } } else { this.WriteException(context, s_fatalException); } } catch (Exception exception3) { this.WriteException(context, exception3); } }