HttpHostedTransportConfiguration.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Activation / HttpHostedTransportConfiguration.cs / 1 / 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; 

    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 = null; 
                if (object.ReferenceEquals(this.Scheme, Uri.UriSchemeHttp))
                {
                    listenAddress = BaseUriWithWildcard.CreateHttpUri(binding);
                } 
                else
                { 
                    listenAddress = BaseUriWithWildcard.CreateHttpsUri(binding); 
                }
 
                HostedHttpTransportManager httpManager = CreateTransportManager(listenAddress);

                if (httpManager != null)
                { 
                    tempDirectory.Add(httpManager);
                    ListenAddresses.Add(listenAddress); 
                } 
            }
 
            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)
        {
            HostedHttpTransportManager foundTransportManager = null;
            HostedHttpTransportManager weakTransportManager = null; 

            foreach (HostedHttpTransportManager manager in transportManagerDirectory) 
            { 
                if ((string.Compare(manager.Scheme, uri.Scheme, StringComparison.OrdinalIgnoreCase) == 0)
                    && (manager.ListenUri.Port == uri.Port)) 
                {
                    if (manager.HostNameComparisonMode == HostNameComparisonMode.StrongWildcard)
                    {
                        return manager; 
                    }
 
                    if (manager.HostNameComparisonMode == HostNameComparisonMode.WeakWildcard) 
                    {
                        weakTransportManager = manager; 
                    }

                    if ((manager.HostNameComparisonMode == HostNameComparisonMode.Exact)
                        && (string.Compare(manager.ListenUri.Host, uri.Host, StringComparison.OrdinalIgnoreCase) == 0)) 
                    {
                        foundTransportManager = manager; 
                    } 
                }
            } 

            if (foundTransportManager == null)
                foundTransportManager = weakTransportManager;
 
            return foundTransportManager;
        } 
 
        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.


                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK