private void CreateTransportManagers()
        {
            Collection <HostedHttpTransportManager> collection = new Collection <HostedHttpTransportManager>();

            foreach (string str in HostedTransportConfigurationManager.MetabaseSettings.GetBindings(base.Scheme))
            {
                BaseUriWithWildcard listenAddress = BaseUriWithWildcard.CreateHostedUri(base.Scheme, str, HostingEnvironmentWrapper.ApplicationVirtualPath);
                bool flag = false;
                if (ServiceHostingEnvironment.MultipleSiteBindingsEnabled)
                {
                    listenAddress = new BaseUriWithWildcard(listenAddress.BaseAddress, HostNameComparisonMode.WeakWildcard);
                    flag          = true;
                }
                HostedHttpTransportManager item = this.CreateTransportManager(listenAddress);
                if (item != null)
                {
                    collection.Add(item);
                    base.ListenAddresses.Add(listenAddress);
                }
                if (flag)
                {
                    break;
                }
            }
            this.transportManagerDirectory = collection;
        }
        HostedHttpTransportManager CreateTransportManager(BaseUriWithWildcard listenAddress)
        {
            UriPrefixTable <ITransportManagerRegistration> 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);
        }
        private HostedHttpTransportManager CreateTransportManager(BaseUriWithWildcard listenAddress)
        {
            UriPrefixTable <ITransportManagerRegistration> staticTransportManagerTable = null;

            if (object.ReferenceEquals(base.Scheme, Uri.UriSchemeHttp))
            {
                staticTransportManagerTable = HttpChannelListener.StaticTransportManagerTable;
            }
            else
            {
                staticTransportManagerTable = SharedHttpsTransportManager.StaticTransportManagerTable;
            }
            HostedHttpTransportManager item = null;

            lock (staticTransportManagerTable)
            {
                ITransportManagerRegistration registration;
                if (!staticTransportManagerTable.TryLookupUri(listenAddress.BaseAddress, listenAddress.HostNameComparisonMode, out registration))
                {
                    item = new HostedHttpTransportManager(listenAddress);
                    staticTransportManagerTable.RegisterUri(listenAddress.BaseAddress, listenAddress.HostNameComparisonMode, item);
                }
            }
            return(item);
        }
        HostedHttpTransportManager CreateTransportManager(BaseUriWithWildcard listenAddress)
        {
            UriPrefixTable<ITransportManagerRegistration> 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;
        }
Esempio n. 5
0
        private void HandleRequest()
        {
            string aspNetRouteServiceVirtualPath;

            this.OriginalRequestUri = this.GetUrl();
            if (!string.IsNullOrEmpty(this.AspNetRouteServiceVirtualPath))
            {
                aspNetRouteServiceVirtualPath = this.AspNetRouteServiceVirtualPath;
            }
            else if (!string.IsNullOrEmpty(this.configurationBasedServiceVirtualPath))
            {
                aspNetRouteServiceVirtualPath = this.configurationBasedServiceVirtualPath;
            }
            else
            {
                aspNetRouteServiceVirtualPath = this.GetAppRelativeCurrentExecutionFilePath();
            }
            if (this.ensureWFService)
            {
                bool flag = false;
                try
                {
                    if (!ServiceHostingEnvironment.EnsureWorkflowService(aspNetRouteServiceVirtualPath))
                    {
                        this.CompleteOperation(null);
                        flag = true;
                        return;
                    }
                }
                finally
                {
                    if (!flag)
                    {
                        this.CompleteRequest();
                    }
                }
            }
            if (ServiceHostingEnvironment.IsSimpleApplicationHost)
            {
                HostedTransportConfigurationManager.EnsureInitializedForSimpleApplicationHost(this);
            }
            HttpHostedTransportConfiguration configuration        = HostedTransportConfigurationManager.GetConfiguration(this.OriginalRequestUri.Scheme) as HttpHostedTransportConfiguration;
            HostedHttpTransportManager       httpTransportManager = null;

            if (configuration != null)
            {
                httpTransportManager = configuration.GetHttpTransportManager(this.OriginalRequestUri);
            }
            if (httpTransportManager == null)
            {
                InvalidOperationException  innerException      = new InvalidOperationException(System.ServiceModel.Activation.SR.Hosting_TransportBindingNotFound(this.OriginalRequestUri.ToString()));
                ServiceActivationException activationException = new ServiceActivationException(innerException.Message, innerException);
                this.LogServiceActivationException(activationException);
                throw System.ServiceModel.Activation.FxTrace.Exception.AsError(activationException);
            }
            this.RequestUri = new Uri(httpTransportManager.ListenUri, this.OriginalRequestUri.PathAndQuery);
            ServiceHostingEnvironment.EnsureServiceAvailableFast(aspNetRouteServiceVirtualPath);
            httpTransportManager.HttpContextReceived(this);
        }
        internal HostedHttpTransportManager GetHttpTransportManager(Uri uri)
        {
            if (ServiceHostingEnvironment.MultipleSiteBindingsEnabled)
            {
                return(this.transportManagerDirectory[0]);
            }
            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(null);
                }
                return(manager);
            }
            }
            HostedHttpTransportManager manager2 = null;
            HostedHttpTransportManager manager3 = null;
            string scheme = uri.Scheme;
            int    port   = uri.Port;
            string str2   = null;

            foreach (HostedHttpTransportManager manager4 in this.transportManagerDirectory)
            {
                if ((manager4.Port == port) && (string.Compare(manager4.Scheme, scheme, StringComparison.OrdinalIgnoreCase) == 0))
                {
                    if (manager4.HostNameComparisonMode == HostNameComparisonMode.StrongWildcard)
                    {
                        return(manager4);
                    }
                    if (manager4.HostNameComparisonMode == HostNameComparisonMode.WeakWildcard)
                    {
                        manager3 = manager4;
                    }
                    if ((manager4.HostNameComparisonMode == HostNameComparisonMode.Exact) && (string.Compare(manager4.Host, str2 ?? (str2 = uri.Host), StringComparison.OrdinalIgnoreCase) == 0))
                    {
                        manager2 = manager4;
                    }
                }
            }
            return(manager2 ?? manager3);
        }
 private HostedHttpTransportManager CreateTransportManager(BaseUriWithWildcard listenAddress)
 {
     UriPrefixTable<ITransportManagerRegistration> staticTransportManagerTable = null;
     if (object.ReferenceEquals(base.Scheme, Uri.UriSchemeHttp))
     {
         staticTransportManagerTable = HttpChannelListener.StaticTransportManagerTable;
     }
     else
     {
         staticTransportManagerTable = SharedHttpsTransportManager.StaticTransportManagerTable;
     }
     HostedHttpTransportManager item = null;
     lock (staticTransportManagerTable)
     {
         ITransportManagerRegistration registration;
         if (!staticTransportManagerTable.TryLookupUri(listenAddress.BaseAddress, listenAddress.HostNameComparisonMode, out registration))
         {
             item = new HostedHttpTransportManager(listenAddress);
             staticTransportManagerTable.RegisterUri(listenAddress.BaseAddress, listenAddress.HostNameComparisonMode, item);
         }
     }
     return item;
 }
        void CreateTransportManagers()
        {
            Collection <HostedHttpTransportManager> tempDirectory = new Collection <HostedHttpTransportManager>();

            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;
        }
        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.NormalizedHost(), 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.NormalizedHost()),
                                            StringComparison.OrdinalIgnoreCase) == 0))
                        {
                            foundTransportManager = manager;
                        }
                    }
                }

                return(foundTransportManager ?? weakTransportManager);
            }
            }
        }
        void HandleRequest()
        {
            this.OriginalRequestUri = GetUrl();
            string relativeVirtualPath;

            if (!string.IsNullOrEmpty(this.AspNetRouteServiceVirtualPath))
            {
                relativeVirtualPath = this.AspNetRouteServiceVirtualPath;
            }
            else if (!string.IsNullOrEmpty(this.configurationBasedServiceVirtualPath))
            {
                relativeVirtualPath = this.configurationBasedServiceVirtualPath;
            }
            else
            {
                relativeVirtualPath = GetAppRelativeCurrentExecutionFilePath();
            }

            if (ensureWFService)
            {
                bool bypass = false;
                try
                {
                    if (!ServiceHostingEnvironment.EnsureWorkflowService(relativeVirtualPath))
                    {
                        CompleteOperation(null);
                        bypass = true;
                        return;
                    }
                }
                finally
                {
                    if (!bypass)
                    {
                        CompleteRequest();
                    }
                }
            }

            // Support for Cassini.
            if (ServiceHostingEnvironment.IsSimpleApplicationHost)
            {
                HostedTransportConfigurationManager.EnsureInitializedForSimpleApplicationHost(this);
            }

            HttpHostedTransportConfiguration transportConfiguration = HostedTransportConfigurationManager.GetConfiguration(this.OriginalRequestUri.Scheme)
                                                                      as HttpHostedTransportConfiguration;
            HostedHttpTransportManager transportManager = null;

            // There must be a transport binding that matches the request.
            if (transportConfiguration != null)
            {
                transportManager = transportConfiguration.GetHttpTransportManager(this.OriginalRequestUri);
            }

            if (transportManager == null)
            {
                InvalidOperationException invalidOpException = new InvalidOperationException(SR.Hosting_TransportBindingNotFound(OriginalRequestUri.ToString()));

                ServiceActivationException activationException = new ServiceActivationException(invalidOpException.Message, invalidOpException);

                LogServiceActivationException(activationException);

                throw FxTrace.Exception.AsError(activationException);
            }

            this.RequestUri = new Uri(transportManager.ListenUri, this.OriginalRequestUri.PathAndQuery);
            Fx.Assert(
                object.ReferenceEquals(this.RequestUri.Scheme, Uri.UriSchemeHttp) || object.ReferenceEquals(this.RequestUri.Scheme, Uri.UriSchemeHttps),
                "Scheme must be Http or Https.");

            ServiceHostingEnvironment.EnsureServiceAvailableFast(relativeVirtualPath, this.eventTraceActivity);

            transportManager.HttpContextReceived(this);
        }