Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WCF / System.ServiceModel.Activation / System / ServiceModel / Activation / HttpHostedTransportConfiguration.cs / 1305376 / HttpHostedTransportConfiguration.cs
//---------------------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------------------- namespace System.ServiceModel.Activation { using System.Collections; using System.ServiceModel; using System.ServiceModel.Channels; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.Globalization; using System.Net; using System.Security; using System.Runtime; class HttpHostedTransportConfiguration : HostedTransportConfigurationBase { CollectiontransportManagerDirectory; internal protected HttpHostedTransportConfiguration(string scheme) : base(scheme) { CreateTransportManagers(); } internal HttpHostedTransportConfiguration() : this(Uri.UriSchemeHttp) {} HostedHttpTransportManager CreateTransportManager(BaseUriWithWildcard listenAddress) { UriPrefixTable table = null; if (object.ReferenceEquals(this.Scheme, Uri.UriSchemeHttp)) { table = HttpChannelListener.StaticTransportManagerTable; } else { table = SharedHttpsTransportManager.StaticTransportManagerTable; } HostedHttpTransportManager httpManager = null; lock (table) { ITransportManagerRegistration registration; if (!table.TryLookupUri(listenAddress.BaseAddress, listenAddress.HostNameComparisonMode, out registration)) { httpManager = new HostedHttpTransportManager(listenAddress); table.RegisterUri(listenAddress.BaseAddress, listenAddress.HostNameComparisonMode, httpManager); } } return httpManager; } void CreateTransportManagers() { Collection tempDirectory = new Collection (); string[] bindings = HostedTransportConfigurationManager.MetabaseSettings.GetBindings(this.Scheme); foreach (string binding in bindings) { TryDebugPrint("HttpHostedTransportConfiguration.CreateTransportManagers() adding binding: " + binding); BaseUriWithWildcard listenAddress = BaseUriWithWildcard.CreateHostedUri(this.Scheme, binding, HostingEnvironmentWrapper.ApplicationVirtualPath); bool done = false; if (ServiceHostingEnvironment.MultipleSiteBindingsEnabled) { //In this specific mode we only create one transport manager and all the //hosted channel listeners hang off of this transport manager listenAddress = new BaseUriWithWildcard(listenAddress.BaseAddress, HostNameComparisonMode.WeakWildcard); done = true; } HostedHttpTransportManager httpManager = CreateTransportManager(listenAddress); //httpManager will be null when 2 site bindings differ only in ip address if (httpManager != null) { tempDirectory.Add(httpManager); ListenAddresses.Add(listenAddress); } if (done) { break; } } transportManagerDirectory = tempDirectory; } static bool canDebugPrint = true; [Conditional("DEBUG")] static void TryDebugPrint(string message) { if (canDebugPrint) { try { Debug.Print(message); } catch (SecurityException e) { canDebugPrint = false; // not re-throwing on purpose if (DiagnosticUtility.ShouldTraceWarning) { DiagnosticUtility.ExceptionUtility.TraceHandledException(e, TraceEventType.Warning); } } } } internal HostedHttpTransportManager GetHttpTransportManager(Uri uri) { if (ServiceHostingEnvironment.MultipleSiteBindingsEnabled) { Fx.Assert(transportManagerDirectory.Count == 1, "There should be only one TM in this mode"); return transportManagerDirectory[0]; } // Optimized common cases without having to create an enumerator. switch (this.transportManagerDirectory.Count) { case 0: return null; case 1: { HostedHttpTransportManager manager = this.transportManagerDirectory[0]; if (manager.Port == uri.Port && (string.Compare(manager.Scheme, uri.Scheme, StringComparison.OrdinalIgnoreCase) == 0) && (manager.HostNameComparisonMode != HostNameComparisonMode.Exact || string.Compare(manager.ListenUri.Host, uri.Host, StringComparison.OrdinalIgnoreCase) == 0)) { return manager; } return null; } default: { HostedHttpTransportManager foundTransportManager = null; HostedHttpTransportManager weakTransportManager = null; string scheme = uri.Scheme; int port = uri.Port; string host = null; foreach (HostedHttpTransportManager manager in this.transportManagerDirectory) { if (manager.Port == port && string.Compare(manager.Scheme, scheme, StringComparison.OrdinalIgnoreCase) == 0) { if (manager.HostNameComparisonMode == HostNameComparisonMode.StrongWildcard) { return manager; } if (manager.HostNameComparisonMode == HostNameComparisonMode.WeakWildcard) { weakTransportManager = manager; } if ((manager.HostNameComparisonMode == HostNameComparisonMode.Exact) && (string.Compare(manager.Host, host ?? (host = uri.Host), StringComparison.OrdinalIgnoreCase) == 0)) { foundTransportManager = manager; } } } return foundTransportManager ?? weakTransportManager; } } } public override Uri[] GetBaseAddresses(string virtualPath) { // Special casing SSL settings. if (string.CompareOrdinal(this.Scheme, Uri.UriSchemeHttp) == 0 && !ServiceHostingEnvironment.IsSimpleApplicationHost) { if (HostedTransportConfigurationManager.MetabaseSettings.GetAllowSslOnly(virtualPath)) { return new Uri[0]; } } return base.GetBaseAddresses(virtualPath); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------------------- namespace System.ServiceModel.Activation { using System.Collections; using System.ServiceModel; using System.ServiceModel.Channels; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.Globalization; using System.Net; using System.Security; using System.Runtime; class HttpHostedTransportConfiguration : HostedTransportConfigurationBase { Collection transportManagerDirectory; internal protected HttpHostedTransportConfiguration(string scheme) : base(scheme) { CreateTransportManagers(); } internal HttpHostedTransportConfiguration() : this(Uri.UriSchemeHttp) {} HostedHttpTransportManager CreateTransportManager(BaseUriWithWildcard listenAddress) { UriPrefixTable table = null; if (object.ReferenceEquals(this.Scheme, Uri.UriSchemeHttp)) { table = HttpChannelListener.StaticTransportManagerTable; } else { table = SharedHttpsTransportManager.StaticTransportManagerTable; } HostedHttpTransportManager httpManager = null; lock (table) { ITransportManagerRegistration registration; if (!table.TryLookupUri(listenAddress.BaseAddress, listenAddress.HostNameComparisonMode, out registration)) { httpManager = new HostedHttpTransportManager(listenAddress); table.RegisterUri(listenAddress.BaseAddress, listenAddress.HostNameComparisonMode, httpManager); } } return httpManager; } void CreateTransportManagers() { Collection tempDirectory = new Collection (); string[] bindings = HostedTransportConfigurationManager.MetabaseSettings.GetBindings(this.Scheme); foreach (string binding in bindings) { TryDebugPrint("HttpHostedTransportConfiguration.CreateTransportManagers() adding binding: " + binding); BaseUriWithWildcard listenAddress = BaseUriWithWildcard.CreateHostedUri(this.Scheme, binding, HostingEnvironmentWrapper.ApplicationVirtualPath); bool done = false; if (ServiceHostingEnvironment.MultipleSiteBindingsEnabled) { //In this specific mode we only create one transport manager and all the //hosted channel listeners hang off of this transport manager listenAddress = new BaseUriWithWildcard(listenAddress.BaseAddress, HostNameComparisonMode.WeakWildcard); done = true; } HostedHttpTransportManager httpManager = CreateTransportManager(listenAddress); //httpManager will be null when 2 site bindings differ only in ip address if (httpManager != null) { tempDirectory.Add(httpManager); ListenAddresses.Add(listenAddress); } if (done) { break; } } transportManagerDirectory = tempDirectory; } static bool canDebugPrint = true; [Conditional("DEBUG")] static void TryDebugPrint(string message) { if (canDebugPrint) { try { Debug.Print(message); } catch (SecurityException e) { canDebugPrint = false; // not re-throwing on purpose if (DiagnosticUtility.ShouldTraceWarning) { DiagnosticUtility.ExceptionUtility.TraceHandledException(e, TraceEventType.Warning); } } } } internal HostedHttpTransportManager GetHttpTransportManager(Uri uri) { if (ServiceHostingEnvironment.MultipleSiteBindingsEnabled) { Fx.Assert(transportManagerDirectory.Count == 1, "There should be only one TM in this mode"); return transportManagerDirectory[0]; } // Optimized common cases without having to create an enumerator. switch (this.transportManagerDirectory.Count) { case 0: return null; case 1: { HostedHttpTransportManager manager = this.transportManagerDirectory[0]; if (manager.Port == uri.Port && (string.Compare(manager.Scheme, uri.Scheme, StringComparison.OrdinalIgnoreCase) == 0) && (manager.HostNameComparisonMode != HostNameComparisonMode.Exact || string.Compare(manager.ListenUri.Host, uri.Host, StringComparison.OrdinalIgnoreCase) == 0)) { return manager; } return null; } default: { HostedHttpTransportManager foundTransportManager = null; HostedHttpTransportManager weakTransportManager = null; string scheme = uri.Scheme; int port = uri.Port; string host = null; foreach (HostedHttpTransportManager manager in this.transportManagerDirectory) { if (manager.Port == port && string.Compare(manager.Scheme, scheme, StringComparison.OrdinalIgnoreCase) == 0) { if (manager.HostNameComparisonMode == HostNameComparisonMode.StrongWildcard) { return manager; } if (manager.HostNameComparisonMode == HostNameComparisonMode.WeakWildcard) { weakTransportManager = manager; } if ((manager.HostNameComparisonMode == HostNameComparisonMode.Exact) && (string.Compare(manager.Host, host ?? (host = uri.Host), StringComparison.OrdinalIgnoreCase) == 0)) { foundTransportManager = manager; } } } return foundTransportManager ?? weakTransportManager; } } } public override Uri[] GetBaseAddresses(string virtualPath) { // Special casing SSL settings. if (string.CompareOrdinal(this.Scheme, Uri.UriSchemeHttp) == 0 && !ServiceHostingEnvironment.IsSimpleApplicationHost) { if (HostedTransportConfigurationManager.MetabaseSettings.GetAllowSslOnly(virtualPath)) { return new Uri[0]; } } return base.GetBaseAddresses(virtualPath); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- XmlSchemaSimpleType.cs
- DelegateTypeInfo.cs
- InstanceNormalEvent.cs
- FormView.cs
- XPathArrayIterator.cs
- ISAPIRuntime.cs
- ListBindingConverter.cs
- PhysicalOps.cs
- BitmapEffectrendercontext.cs
- FunctionImportElement.cs
- DataTableCollection.cs
- X509IssuerSerialKeyIdentifierClause.cs
- XmlSchemaParticle.cs
- FormattedText.cs
- TraceContextRecord.cs
- FileLoadException.cs
- SharedConnectionWorkflowTransactionService.cs
- NetworkInformationPermission.cs
- MenuCommand.cs
- DomainLiteralReader.cs
- CryptoStream.cs
- XmlNotation.cs
- DeclarationUpdate.cs
- ActiveXHost.cs
- SaveFileDialogDesigner.cs
- Soap12ServerProtocol.cs
- DbReferenceCollection.cs
- ImageListStreamer.cs
- DateTimeValueSerializerContext.cs
- PageBuildProvider.cs
- IERequestCache.cs
- KnownTypesProvider.cs
- LineMetrics.cs
- ProfileGroupSettings.cs
- EncryptedPackage.cs
- ApplicationSettingsBase.cs
- ArglessEventHandlerProxy.cs
- LessThanOrEqual.cs
- MultiByteCodec.cs
- HelpEvent.cs
- AccessViolationException.cs
- UrlMappingCollection.cs
- KnownTypesProvider.cs
- PriorityBinding.cs
- QuotaExceededException.cs
- SafeFileMappingHandle.cs
- TraceUtility.cs
- TagMapCollection.cs
- SortExpressionBuilder.cs
- AnnotationDocumentPaginator.cs
- serverconfig.cs
- IMembershipProvider.cs
- ComplexTypeEmitter.cs
- LongTypeConverter.cs
- LinkedResource.cs
- NamedObjectList.cs
- altserialization.cs
- HostnameComparisonMode.cs
- GeneralTransform3D.cs
- TargetControlTypeCache.cs
- PagedDataSource.cs
- ViewSimplifier.cs
- QuaternionAnimation.cs
- ToolTipService.cs
- ViewManager.cs
- MaskInputRejectedEventArgs.cs
- XmlSchemaAnyAttribute.cs
- WebBrowserDocumentCompletedEventHandler.cs
- PlainXmlSerializer.cs
- SemanticKeyElement.cs
- InkCollectionBehavior.cs
- DerivedKeyCachingSecurityTokenSerializer.cs
- TraceFilter.cs
- CodeTypeReference.cs
- ListItemConverter.cs
- RegexStringValidator.cs
- PropertyIDSet.cs
- DataControlFieldsEditor.cs
- Cursors.cs
- SchemaImporterExtensionsSection.cs
- RightsManagementInformation.cs
- File.cs
- HtmlHead.cs
- ObjectQueryExecutionPlan.cs
- MailMessageEventArgs.cs
- TypeExtension.cs
- Aggregates.cs
- ProcessStartInfo.cs
- HttpConfigurationSystem.cs
- PreservationFileWriter.cs
- SqlStream.cs
- ToolStrip.cs
- UserInitiatedNavigationPermission.cs
- HttpModuleActionCollection.cs
- RolePrincipal.cs
- PropertyGeneratedEventArgs.cs
- SqlBuilder.cs
- SendSecurityHeader.cs
- XmlSchemaAttributeGroupRef.cs
- EventPrivateKey.cs