示例#1
0
        public ContractInfo(Guid iid,
                            ServiceEndpointElement endpoint,
                            ComCatalogObject interfaceObject,
                            ComCatalogObject application)
        {
            this.name = endpoint.Contract;
            this.iid  = iid;

            // Interface Roles
            //
            ComCatalogCollection roles;

            roles = interfaceObject.GetCollection("RolesForInterface");
            this.interfaceRoleMembers = CatalogUtil.GetRoleMembers(application,
                                                                   roles);

            // Operations
            //
            this.operations = new List <OperationInfo>();

            ComCatalogCollection methods;

            methods = interfaceObject.GetCollection("MethodsForInterface");
            foreach (ComCatalogObject method in methods)
            {
                this.operations.Add(new OperationInfo(method,
                                                      application));
            }
        }
示例#2
0
        public OperationInfo(ComCatalogObject methodObject, ComCatalogObject application)
        {
            this.name = (string)methodObject.GetValue("Name");
            ComCatalogCollection collection = methodObject.GetCollection("RolesForMethod");

            this.methodRoleMembers = CatalogUtil.GetRoleMembers(application, collection);
        }
        public ContractInfo(Guid iid, ServiceEndpointElement endpoint, ComCatalogObject interfaceObject, ComCatalogObject application)
        {
            this.name = endpoint.Contract;
            this.iid  = iid;
            ComCatalogCollection collection = interfaceObject.GetCollection("RolesForInterface");

            this.interfaceRoleMembers = CatalogUtil.GetRoleMembers(application, collection);
            this.operations           = new List <OperationInfo>();
            ComCatalogCollection.Enumerator enumerator = interfaceObject.GetCollection("MethodsForInterface").GetEnumerator();
            while (enumerator.MoveNext())
            {
                ComCatalogObject current = enumerator.Current;
                this.operations.Add(new OperationInfo(current, application));
            }
        }
示例#4
0
        // NOTE: Construction of this thing is quite inefficient-- it
        //       has several nested loops that could probably be
        //       improved. Such optimizations have been left for when
        //       it turns out to be a performance problem, for the
        //       sake of simplicity.
        //
        public ServiceInfo(Guid clsid,
                           ServiceElement service,
                           ComCatalogObject application,
                           ComCatalogObject classObject,
                           HostingMode hostingMode)
        {
            // Simple things...
            //
            this.service           = service;
            this.clsid             = clsid;
            this.appid             = Fx.CreateGuid((string)application.GetValue("ID"));
            this.partitionId       = Fx.CreateGuid((string)application.GetValue("AppPartitionID"));
            this.bitness           = (Bitness)classObject.GetValue("Bitness");
            this.transactionOption = (TransactionOption)classObject.GetValue("Transaction");
            this.hostingMode       = hostingMode;
            this.managedType       = TypeCacheManager.ResolveClsidToType(clsid);
            this.serviceName       = application.Name + "." + classObject.Name;
            this.udts = new Dictionary <Guid, List <Type> >();

            // Isolation Level
            COMAdminIsolationLevel adminIsolationLevel;

            adminIsolationLevel = (COMAdminIsolationLevel)classObject.GetValue("TxIsolationLevel");
            switch (adminIsolationLevel)
            {
            case COMAdminIsolationLevel.Any:
                this.isolationLevel = IsolationLevel.Unspecified;
                break;

            case COMAdminIsolationLevel.ReadUncommitted:
                this.isolationLevel = IsolationLevel.ReadUncommitted;
                break;

            case COMAdminIsolationLevel.ReadCommitted:
                this.isolationLevel = IsolationLevel.ReadCommitted;
                break;

            case COMAdminIsolationLevel.RepeatableRead:
                this.isolationLevel = IsolationLevel.RepeatableRead;
                break;

            case COMAdminIsolationLevel.Serializable:
                this.isolationLevel = IsolationLevel.Serializable;
                break;

            default:
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(
                                                                              SR.GetString(SR.InvalidIsolationLevelValue,
                                                                                           this.clsid, adminIsolationLevel)));
            }

            // Threading Model
            //
            COMAdminThreadingModel adminThreadingModel;

            adminThreadingModel = (COMAdminThreadingModel)classObject.GetValue("ThreadingModel");
            switch (adminThreadingModel)
            {
            case COMAdminThreadingModel.Apartment:
            case COMAdminThreadingModel.Main:
                this.threadingModel  = ThreadingModel.STA;
                objectPoolingEnabled = false;
                break;

            default:
                this.threadingModel  = ThreadingModel.MTA;
                objectPoolingEnabled = (bool)classObject.GetValue("ObjectPoolingEnabled");
                break;
            }

            // Object Pool settings
            //

            if (objectPoolingEnabled)
            {
                maxPoolSize = (int)classObject.GetValue("MaxPoolSize");
            }
            else
            {
                maxPoolSize = 0;
            }
            // Security Settings
            //
            bool appSecurityEnabled;

            appSecurityEnabled = (bool)application.GetValue(
                "ApplicationAccessChecksEnabled");
            if (appSecurityEnabled)
            {
                bool classSecurityEnabled;
                classSecurityEnabled = (bool)classObject.GetValue(
                    "ComponentAccessChecksEnabled");
                if (classSecurityEnabled)
                {
                    this.checkRoles = true;
                }
            }

            // Component Roles
            //
            ComCatalogCollection roles;

            roles = classObject.GetCollection("RolesForComponent");
            this.componentRoleMembers = CatalogUtil.GetRoleMembers(application, roles);
            // Contracts
            // One ContractInfo per unique IID exposed, so we need to
            // filter duplicates.
            //
            this.contracts = new List <ContractInfo>();
            ComCatalogCollection interfaces;

            interfaces = classObject.GetCollection("InterfacesForComponent");
            foreach (ServiceEndpointElement endpoint in service.Endpoints)
            {
                ContractInfo contract = null;
                if (endpoint.Contract == ServiceMetadataBehavior.MexContractName)
                {
                    continue;
                }

                Guid iid;
                if (DiagnosticUtility.Utility.TryCreateGuid(endpoint.Contract, out iid))
                {
                    // (Filter duplicates.)
                    bool duplicate = false;
                    foreach (ContractInfo otherContract in this.contracts)
                    {
                        if (iid == otherContract.IID)
                        {
                            duplicate = true;
                            break;
                        }
                    }
                    if (duplicate)
                    {
                        continue;
                    }

                    foreach (ComCatalogObject interfaceObject in interfaces)
                    {
                        Guid otherInterfaceID;
                        if (DiagnosticUtility.Utility.TryCreateGuid((string)interfaceObject.GetValue("IID"), out otherInterfaceID))
                        {
                            if (otherInterfaceID == iid)
                            {
                                contract = new ContractInfo(iid,
                                                            endpoint,
                                                            interfaceObject,
                                                            application);
                                break;
                            }
                        }
                    }
                }

                if (contract == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(
                                                                                  SR.GetString(SR.EndpointNotAnIID,
                                                                                               clsid.ToString("B").ToUpperInvariant(),
                                                                                               endpoint.Contract)));
                }
                this.contracts.Add(contract);
            }
        }
        public void Startup(IProcessInitControl control)
        {
            // Find our application object, and associated components
            // (classes) collection from the COM+ catalog.
            //
            applicationId = ContextUtil.ApplicationId;

            ComPlusDllHostInitializerTrace.Trace(TraceEventType.Information, TraceCode.ComIntegrationDllHostInitializerStarting,
                                                 SR.TraceCodeComIntegrationDllHostInitializerStarting, applicationId);

            Thread pingThread = null;

            try
            {
                pingThread = new Thread(PingProc);
                pingThread.Start(control);

                ComCatalogObject application;
                application = CatalogUtil.FindApplication(applicationId);
                if (application == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(
                                                                                  SR.GetString(SR.ApplicationNotFound,
                                                                                               applicationId.ToString("B").ToUpperInvariant())));
                }

                bool processPooled = ((int)application.GetValue("ConcurrentApps")) > 1;
                if (processPooled)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(
                                                                                  SR.GetString(SR.PooledApplicationNotSupportedForComplusHostedScenarios,
                                                                                               applicationId.ToString("B").ToUpperInvariant())));
                }

                bool processRecycled = ((int)application.GetValue("RecycleLifetimeLimit")) > 0 ||
                                       ((int)application.GetValue("RecycleCallLimit")) > 0 ||
                                       ((int)application.GetValue("RecycleActivationLimit")) > 0 ||
                                       ((int)application.GetValue("RecycleMemoryLimit")) > 0;

                if (processRecycled)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(
                                                                                  SR.GetString(SR.RecycledApplicationNotSupportedForComplusHostedScenarios,
                                                                                               applicationId.ToString("B").ToUpperInvariant())));
                }


                ComCatalogCollection classes;
                classes = application.GetCollection("Components");

                // Load up Indigo configuration.
                //
                ServicesSection services     = ServicesSection.GetSection();
                bool            foundService = false;


                foreach (ServiceElement service in services.Services)
                {
                    Guid clsidToCompare = Guid.Empty;
                    Guid appIdToCompare = Guid.Empty;

                    string[] serviceParams = service.Name.Split(',');
                    if (serviceParams.Length != 2)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.OnlyClsidsAllowedForServiceType, service.Name)));
                    }

                    if (!DiagnosticUtility.Utility.TryCreateGuid(serviceParams[0], out appIdToCompare))
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.OnlyClsidsAllowedForServiceType, service.Name)));
                    }

                    if (!DiagnosticUtility.Utility.TryCreateGuid(serviceParams[1], out clsidToCompare))
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.OnlyClsidsAllowedForServiceType, service.Name)));
                    }

                    foundService = false;

                    // CODEWORK: Consider farming this out across multiple threadpool threads.
                    // When it was discovered that startup time could be a problem it was too late
                    // to to do that since it can cause failure conditions that need to be considered
                    // (such as the threadpool running out) so we decided not to touch that part.
                    // But since this can potentially take a very long time on big COM apps
                    // it should be parallelized at some point.
                    foreach (ComCatalogObject classObject in classes)
                    {
                        Guid clsid = Fx.CreateGuid((string)classObject.GetValue("CLSID"));

                        if (clsid == clsidToCompare && applicationId == appIdToCompare)
                        {
                            foundService = true;
                            ComPlusDllHostInitializerTrace.Trace(TraceEventType.Verbose, TraceCode.ComIntegrationDllHostInitializerAddingHost,
                                                                 SR.TraceCodeComIntegrationDllHostInitializerAddingHost, applicationId, clsid, service);
                            this.hosts.Add(
                                new DllHostedComPlusServiceHost(clsid,
                                                                service,
                                                                application,
                                                                classObject));
                        }
                    }
                    if (!foundService)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString
                                                                                                                    (SR.CannotFindClsidInApplication, clsidToCompare.ToString("B").ToUpperInvariant(), applicationId.ToString("B").ToUpperInvariant())));
                    }
                }
                if (foundService == false)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.DllHostInitializerFoundNoServices());
                }

                foreach (ComPlusServiceHost host in this.hosts)
                {
                    host.Open();
                }
            }
            catch (Exception e)
            {
                DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error,
                                                    (ushort)System.Runtime.Diagnostics.EventLogCategory.ComPlus,
                                                    (uint)System.Runtime.Diagnostics.EventLogEventId.ComPlusDllHostInitializerStartingError,
                                                    applicationId.ToString(),
                                                    e.ToString());
                throw;
            }
            finally
            {
                if (null != pingThread)
                {
                    pingThread.Abort(); // We are done; stop pinging.
                }
            }
            ComPlusDllHostInitializerTrace.Trace(TraceEventType.Information, TraceCode.ComIntegrationDllHostInitializerStarted,
                                                 SR.TraceCodeComIntegrationDllHostInitializerStarted, applicationId);
        }
        public WebHostedComPlusServiceHost(string webhostParams, Uri[] baseAddresses)
        {
            Guid        guid;
            Guid        guid2;
            HostingMode webHostInProcess;

            foreach (Uri uri in baseAddresses)
            {
                base.InternalBaseAddresses.Add(uri);
            }
            string[] strArray = webhostParams.Split(new char[] { ',' });
            if (strArray.Length != 2)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(System.ServiceModel.SR.GetString("ServiceStringFormatError", new object[] { webhostParams })));
            }
            if (!DiagnosticUtility.Utility.TryCreateGuid(strArray[0], out guid))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(System.ServiceModel.SR.GetString("ServiceStringFormatError", new object[] { webhostParams })));
            }
            if (!DiagnosticUtility.Utility.TryCreateGuid(strArray[1], out guid2))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(System.ServiceModel.SR.GetString("ServiceStringFormatError", new object[] { webhostParams })));
            }
            string           str = guid.ToString("B").ToUpperInvariant();
            ComCatalogObject applicationObject = CatalogUtil.FindApplication(guid2);

            if (applicationObject == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(System.ServiceModel.SR.GetString("ApplicationNotFound", new object[] { guid2.ToString("B").ToUpperInvariant() })));
            }
            ComCatalogCollection collection  = applicationObject.GetCollection("Components");
            ComCatalogObject     classObject = null;

            ComCatalogCollection.Enumerator enumerator = collection.GetEnumerator();
            while (enumerator.MoveNext())
            {
                ComCatalogObject current = enumerator.Current;
                string           str2    = (string)current.GetValue("CLSID");
                if (str.Equals(str2, StringComparison.OrdinalIgnoreCase))
                {
                    classObject = current;
                    break;
                }
            }
            if (classObject == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(System.ServiceModel.SR.GetString("ClsidNotInApplication", new object[] { str, guid2.ToString("B").ToUpperInvariant() })));
            }
            ServicesSection section = ServicesSection.GetSection();
            ServiceElement  service = null;

            foreach (ServiceElement element2 in section.Services)
            {
                Guid     empty     = Guid.Empty;
                Guid     result    = Guid.Empty;
                string[] strArray2 = element2.Name.Split(new char[] { ',' });
                if ((((strArray2.Length == 2) && DiagnosticUtility.Utility.TryCreateGuid(strArray2[0], out result)) && (DiagnosticUtility.Utility.TryCreateGuid(strArray2[1], out empty) && (empty == guid))) && (result == guid2))
                {
                    service = element2;
                    break;
                }
            }
            if (service == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(System.ServiceModel.SR.GetString("ClsidNotInConfiguration", new object[] { str })));
            }
            if (((int)applicationObject.GetValue("Activation")) == 0)
            {
                webHostInProcess = HostingMode.WebHostInProcess;
            }
            else
            {
                webHostInProcess = HostingMode.WebHostOutOfProcess;
            }
            base.Initialize(guid, service, applicationObject, classObject, webHostInProcess);
        }
示例#7
0
        public void Startup(IProcessInitControl control)
        {
            this.applicationId = ContextUtil.ApplicationId;
            ComPlusDllHostInitializerTrace.Trace(TraceEventType.Information, 0x50008, "TraceCodeComIntegrationDllHostInitializerStarting", this.applicationId);
            Thread thread = null;

            try
            {
                thread = new Thread(new ParameterizedThreadStart(DllHostInitializeWorker.PingProc));
                thread.Start(control);
                ComCatalogObject applicationObject = CatalogUtil.FindApplication(this.applicationId);
                if (applicationObject == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(System.ServiceModel.SR.GetString("ApplicationNotFound", new object[] { this.applicationId.ToString("B").ToUpperInvariant() })));
                }
                if (((int)applicationObject.GetValue("ConcurrentApps")) > 1)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(System.ServiceModel.SR.GetString("PooledApplicationNotSupportedForComplusHostedScenarios", new object[] { this.applicationId.ToString("B").ToUpperInvariant() })));
                }
                if ((((((int)applicationObject.GetValue("RecycleLifetimeLimit")) > 0) || (((int)applicationObject.GetValue("RecycleCallLimit")) > 0)) || (((int)applicationObject.GetValue("RecycleActivationLimit")) > 0)) || (((int)applicationObject.GetValue("RecycleMemoryLimit")) > 0))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(System.ServiceModel.SR.GetString("RecycledApplicationNotSupportedForComplusHostedScenarios", new object[] { this.applicationId.ToString("B").ToUpperInvariant() })));
                }
                ComCatalogCollection collection = applicationObject.GetCollection("Components");
                ServicesSection      section    = ServicesSection.GetSection();
                bool flag3 = false;
                foreach (ServiceElement element in section.Services)
                {
                    Guid     empty    = Guid.Empty;
                    Guid     result   = Guid.Empty;
                    string[] strArray = element.Name.Split(new char[] { ',' });
                    if (strArray.Length != 2)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("OnlyClsidsAllowedForServiceType", new object[] { element.Name })));
                    }
                    if (!DiagnosticUtility.Utility.TryCreateGuid(strArray[0], out result))
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("OnlyClsidsAllowedForServiceType", new object[] { element.Name })));
                    }
                    if (!DiagnosticUtility.Utility.TryCreateGuid(strArray[1], out empty))
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("OnlyClsidsAllowedForServiceType", new object[] { element.Name })));
                    }
                    flag3 = false;
                    ComCatalogCollection.Enumerator enumerator = collection.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        ComCatalogObject current = enumerator.Current;
                        Guid             clsid   = Fx.CreateGuid((string)current.GetValue("CLSID"));
                        if ((clsid == empty) && (this.applicationId == result))
                        {
                            flag3 = true;
                            ComPlusDllHostInitializerTrace.Trace(TraceEventType.Verbose, 0x50009, "TraceCodeComIntegrationDllHostInitializerAddingHost", this.applicationId, clsid, element);
                            this.hosts.Add(new DllHostedComPlusServiceHost(clsid, element, applicationObject, current));
                        }
                    }
                    if (!flag3)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("CannotFindClsidInApplication", new object[] { empty.ToString("B").ToUpperInvariant(), this.applicationId.ToString("B").ToUpperInvariant() })));
                    }
                }
                if (!flag3)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.DllHostInitializerFoundNoServices());
                }
                foreach (ComPlusServiceHost host in this.hosts)
                {
                    host.Open();
                }
            }
            catch (Exception exception)
            {
                DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, EventLogCategory.ComPlus, (EventLogEventId)(-1073610729), new string[] { this.applicationId.ToString(), exception.ToString() });
                throw;
            }
            finally
            {
                if (thread != null)
                {
                    thread.Abort();
                }
            }
            ComPlusDllHostInitializerTrace.Trace(TraceEventType.Information, 0x5000a, "TraceCodeComIntegrationDllHostInitializerStarted", this.applicationId);
        }
示例#8
0
        public WebHostedComPlusServiceHost(string webhostParams, Uri[] baseAddresses)
        {
            foreach (Uri address in baseAddresses)
            {
                this.InternalBaseAddresses.Add(address);
            }

            // Split up the parameter string into "clsid,appid".
            //
            string[] parameters = webhostParams.Split(',');
            if (parameters.Length != 2)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(System.ServiceModel.ComIntegration.Error.ListenerInitFailed(
                                                                              SR.GetString(SR.ServiceStringFormatError,
                                                                                           webhostParams)));
            }

            Guid clsid;
            Guid appId;

            if (!DiagnosticUtility.Utility.TryCreateGuid(parameters[0], out clsid))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(System.ServiceModel.ComIntegration.Error.ListenerInitFailed(
                                                                              SR.GetString(SR.ServiceStringFormatError,
                                                                                           webhostParams)));
            }

            if (!DiagnosticUtility.Utility.TryCreateGuid(parameters[1], out appId))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(System.ServiceModel.ComIntegration.Error.ListenerInitFailed(
                                                                              SR.GetString(SR.ServiceStringFormatError,
                                                                                           webhostParams)));
            }

            // "B" == "With dashes and curly braces"
            // (The catalog gives us GUIDs in this format)
            //
            string clsidString = clsid.ToString("B").ToUpperInvariant();

            // Look up the COM+ AdminSDK information for this
            // AppID/CLSID pair.
            //
            ComCatalogObject application;

            application = CatalogUtil.FindApplication(appId);
            if (application == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(System.ServiceModel.ComIntegration.Error.ListenerInitFailed(
                                                                              SR.GetString(SR.ApplicationNotFound,
                                                                                           appId.ToString("B").ToUpperInvariant())));
            }

            ComCatalogCollection classes;

            classes = application.GetCollection("Components");

            ComCatalogObject classObject = null;

            foreach (ComCatalogObject tempClassObject in classes)
            {
                string otherClsid = (string)tempClassObject.GetValue("CLSID");
                if (clsidString.Equals(
                        otherClsid,
                        StringComparison.OrdinalIgnoreCase))
                {
                    classObject = tempClassObject;
                    break;
                }
            }

            if (classObject == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(System.ServiceModel.ComIntegration.Error.ListenerInitFailed(
                                                                              SR.GetString(SR.ClsidNotInApplication,
                                                                                           clsidString,
                                                                                           appId.ToString("B").ToUpperInvariant())));
            }

            // Load up Indigo configuration, get the configuration for
            // this service.
            //
            ServicesSection services = ServicesSection.GetSection();
            ServiceElement  service  = null;

            foreach (ServiceElement serviceInConfig in services.Services)
            {
                Guid clsidFromConfig = Guid.Empty;
                Guid appidFromConfig = Guid.Empty;

                string[] serviceParams = serviceInConfig.Name.Split(',');
                if (serviceParams.Length != 2)
                {
                    continue;
                }


                if (!DiagnosticUtility.Utility.TryCreateGuid(serviceParams[0], out appidFromConfig))
                {
                    // We are tolerant of having non COM+ based services
                    // for webhost.
                    continue;
                }

                if (!DiagnosticUtility.Utility.TryCreateGuid(serviceParams[1], out clsidFromConfig))
                {
                    // We are tolerant of having non COM+ based services
                    // for webhost.
                    continue;
                }

                if (clsidFromConfig == clsid && appidFromConfig == appId)
                {
                    service = serviceInConfig;
                    break;
                }
            }
            if (service == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(System.ServiceModel.ComIntegration.Error.ListenerInitFailed(
                                                                              SR.GetString(SR.ClsidNotInConfiguration,
                                                                                           clsidString)));
            }


            // Hosting mode evaluation
            //
            HostingMode hostingMode;
            int         activation = (int)application.GetValue("Activation");

            if (activation == 0)
            {
                hostingMode = HostingMode.WebHostInProcess;
            }
            else
            {
                hostingMode = HostingMode.WebHostOutOfProcess;
            }

            // Now we have everything we need, do common
            // initialization.
            //
            Initialize(clsid,
                       service,
                       application,
                       classObject,
                       hostingMode);
        }
示例#9
0
        public ServiceInfo(Guid clsid, System.ServiceModel.Configuration.ServiceElement service, ComCatalogObject application, ComCatalogObject classObject, System.ServiceModel.ComIntegration.HostingMode hostingMode)
        {
            this.service = service;
            this.clsid = clsid;
            this.appid = Fx.CreateGuid((string) application.GetValue("ID"));
            this.partitionId = Fx.CreateGuid((string) application.GetValue("AppPartitionID"));
            this.bitness = (System.ServiceModel.ComIntegration.Bitness) classObject.GetValue("Bitness");
            this.transactionOption = (System.EnterpriseServices.TransactionOption) classObject.GetValue("Transaction");
            this.hostingMode = hostingMode;
            this.managedType = TypeCacheManager.ResolveClsidToType(clsid);
            this.serviceName = application.Name + "." + classObject.Name;
            this.udts = new Dictionary<Guid, List<Type>>();
            COMAdminIsolationLevel level = (COMAdminIsolationLevel) classObject.GetValue("TxIsolationLevel");
            switch (level)
            {
                case COMAdminIsolationLevel.Any:
                    this.isolationLevel = System.Transactions.IsolationLevel.Unspecified;
                    break;

                case COMAdminIsolationLevel.ReadUncommitted:
                    this.isolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;
                    break;

                case COMAdminIsolationLevel.ReadCommitted:
                    this.isolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
                    break;

                case COMAdminIsolationLevel.RepeatableRead:
                    this.isolationLevel = System.Transactions.IsolationLevel.RepeatableRead;
                    break;

                case COMAdminIsolationLevel.Serializable:
                    this.isolationLevel = System.Transactions.IsolationLevel.Serializable;
                    break;

                default:
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(System.ServiceModel.SR.GetString("InvalidIsolationLevelValue", new object[] { this.clsid, level })));
            }
            switch (((COMAdminThreadingModel) classObject.GetValue("ThreadingModel")))
            {
                case COMAdminThreadingModel.Apartment:
                case COMAdminThreadingModel.Main:
                    this.threadingModel = System.ServiceModel.ComIntegration.ThreadingModel.STA;
                    this.objectPoolingEnabled = false;
                    break;

                default:
                    this.threadingModel = System.ServiceModel.ComIntegration.ThreadingModel.MTA;
                    this.objectPoolingEnabled = (bool) classObject.GetValue("ObjectPoolingEnabled");
                    break;
            }
            if (this.objectPoolingEnabled)
            {
                this.maxPoolSize = (int) classObject.GetValue("MaxPoolSize");
            }
            else
            {
                this.maxPoolSize = 0;
            }
            if (((bool) application.GetValue("ApplicationAccessChecksEnabled")) && ((bool) classObject.GetValue("ComponentAccessChecksEnabled")))
            {
                this.checkRoles = true;
            }
            ComCatalogCollection collection = classObject.GetCollection("RolesForComponent");
            this.componentRoleMembers = CatalogUtil.GetRoleMembers(application, collection);
            this.contracts = new List<ContractInfo>();
            ComCatalogCollection catalogs2 = classObject.GetCollection("InterfacesForComponent");
            foreach (ServiceEndpointElement element in service.Endpoints)
            {
                ContractInfo item = null;
                if (element.Contract != "IMetadataExchange")
                {
                    Guid guid;
                    if (DiagnosticUtility.Utility.TryCreateGuid(element.Contract, out guid))
                    {
                        bool flag3 = false;
                        foreach (ContractInfo info2 in this.contracts)
                        {
                            if (guid == info2.IID)
                            {
                                flag3 = true;
                                break;
                            }
                        }
                        if (flag3)
                        {
                            continue;
                        }
                        ComCatalogCollection.Enumerator enumerator = catalogs2.GetEnumerator();
                        while (enumerator.MoveNext())
                        {
                            Guid guid2;
                            ComCatalogObject current = enumerator.Current;
                            if (DiagnosticUtility.Utility.TryCreateGuid((string) current.GetValue("IID"), out guid2) && (guid2 == guid))
                            {
                                item = new ContractInfo(guid, element, current, application);
                                break;
                            }
                        }
                    }
                    if (item == null)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(System.ServiceModel.SR.GetString("EndpointNotAnIID", new object[] { clsid.ToString("B").ToUpperInvariant(), element.Contract })));
                    }
                    this.contracts.Add(item);
                }
            }
        }