public DllHostedComPlusServiceHost (Guid clsid,
                                     ServiceElement service,
                                     ComCatalogObject applicationObject,
                                     ComCatalogObject classObject)
 {
     Initialize (clsid,
                 service,
                 applicationObject,
                 classObject,
                 HostingMode.ComPlus);
 }
 public static void Trace(TraceEventType type, int traceCode, string description, Guid appid, Guid clsid, ServiceElement service)
 {
     if (DiagnosticUtility.ShouldTrace(type))
     {
         foreach (ServiceEndpointElement element in service.Endpoints)
         {
             ComPlusDllHostInitializerAddingHostSchema schema = new ComPlusDllHostInitializerAddingHostSchema(appid, clsid, service.BehaviorConfiguration, service.Name, element.Address.ToString(), element.BindingConfiguration, element.BindingName, element.BindingNamespace, element.Binding, element.Contract);
             TraceUtility.TraceEvent(type, traceCode, System.ServiceModel.SR.GetString(description), (TraceRecord) schema);
         }
     }
 }
        protected void Initialize (Guid clsid,
                                   ServiceElement service,
                                   ComCatalogObject applicationObject,
                                   ComCatalogObject classObject,
                                   HostingMode hostingMode)
        {
            VerifyFunctionality();         
 
            this.info = new ServiceInfo(clsid,
                                        service,
                                        applicationObject,
                                        classObject,
                                        hostingMode);
            base.InitializeDescription(new UriSchemeKeyedCollection());
        }
        private void GenerateServiceConfiguration()
        {
            // Get a pointer to system.serviceModel section.
            ConfigurationSectionGroup csg = configuration.SectionGroups["system.serviceModel"];
            // Notify if we get a null reference.
            Debug.Assert(csg != null, "system.serviceModel section could not be found in the configuration.");

            if (csg != null)
            {                
                // Get a reference to the client section.
                ClientSection cs = csg.Sections["client"] as ClientSection;
                // Also get a reference to the services section.
                ServicesSection ss = csg.Sections["services"] as ServicesSection;

                // If there is no services section, we create a new one.
                if (ss == null)
                {
                    // Create a new services section.
                    ss = new ServicesSection();
                    // Add it to the sections collection.
                    csg.Sections.Add("services", ss);
                }

                string fqServiceTypeName = GetFullyQulifiedTypeName(GetServiceTypeName());
                ServiceElement se = new ServiceElement(fqServiceTypeName);
                ss.Services.Add(se);

                if (cs != null)
                {
                    foreach (ChannelEndpointElement cee in cs.Endpoints)
                    {
                        // TODO: May be we will want to give an option to use fully qulified interface names
                        // in the endpoints.
                        ServiceEndpointElement see = new ServiceEndpointElement(cee.Address, cee.Contract);
                        see.BehaviorConfiguration = cee.BehaviorConfiguration;
                        see.BindingConfiguration = cee.BindingConfiguration;
                        see.Binding = cee.Binding;
                        se.Endpoints.Add(see);
                    }
                    csg.Sections.Remove("client");
                }
            }
        }
예제 #5
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);
            }
        }
예제 #6
0
        // returns true if added successfully, or false if didnt add due to duplicate.
        protected bool BaseAddEndpointConfig(Configuration config, EndpointConfig endpointConfig)
        {
            ServiceModelSectionGroup sg = ServiceModelSectionGroup.GetSectionGroup(config);
            ServiceElementCollection serviceColl = sg.Services.Services;


            ServiceElement serviceElement = null;

            // Find serviceElement
            foreach (ServiceElement el in serviceColl)
            {
                if (endpointConfig.MatchServiceType(el.Name))
                {
                    serviceElement = el;
                    break;
                }
            }

            if (serviceElement == null)
            {
                // Didn't find one, create new element for this clsid
                serviceElement = new ServiceElement(endpointConfig.ServiceType);
                string baseServiceAddress = BaseServiceAddress(endpointConfig.Appid, endpointConfig.Clsid, endpointConfig.Iid);
                if (!String.IsNullOrEmpty(baseServiceAddress))
                {
                    BaseAddressElement bae = new BaseAddressElement();
                    bae.BaseAddress = baseServiceAddress;
                    serviceElement.Host.BaseAddresses.Add(bae);
                }
                sg.Services.Services.Add(serviceElement);
            }

            if (endpointConfig.IsMexEndpoint)
            {
                EnsureComMetaDataExchangeBehaviorAdded(config);
                serviceElement.BehaviorConfiguration = comServiceBehavior;
            }
            bool methodsAdded = false;
            if (!endpointConfig.IsMexEndpoint)
            {
                methodsAdded = AddComContractToConfig(config, endpointConfig.InterfaceName, endpointConfig.Iid.ToString("B"), endpointConfig.Methods);

            }

            // Now, check if endpoint already exists..
            foreach (ServiceEndpointElement ee in serviceElement.Endpoints)
            {
                bool listenerExists = true;
                if (this is ComplusEndpointConfigContainer)
                    listenerExists = ((ComplusEndpointConfigContainer)this).ListenerComponentExists;

                if (endpointConfig.MatchContract(ee.Contract))
                {
                    if (listenerExists)
                        return methodsAdded; // didn't add due to duplicate
                    else
                        serviceElement.Endpoints.Remove(ee);
                }
            }

            // All right, add the new endpoint now
            ServiceEndpointElement endpointElement = new ServiceEndpointElement(endpointConfig.Address, endpointConfig.ContractType);
            endpointElement.Binding = endpointConfig.BindingType;
            endpointElement.BindingConfiguration = endpointConfig.BindingName;
            serviceElement.Endpoints.Add(endpointElement);

            AddBinding(config);

            return true;
        }
예제 #7
0
 /// <summary>
 /// Initializes a new host instance
 /// </summary>
 /// <param name="serviceType">
 /// The service class type
 /// </param>
 /// <param name="config">
 /// The configuration element for the service
 /// </param>
 public WcfHost(Type serviceType, ServiceElement config)
 {
     this.config = config;
      base.InitializeDescription(serviceType, new UriSchemeKeyedCollection());
 }
 internal ServiceConfigurationTraceRecord(ServiceElement serviceElement)
 {
     this.serviceElement = serviceElement;
 }
		/// <summary>
		/// Outputs the console information when opening a Service.
		/// </summary>
		/// <param name="appConfigService">The application configuration service.</param>
		private static void OutputConsoleInfo(ServiceElement appConfigService)
		{
			Console.WriteLine("Service added: " + appConfigService.Name);
			foreach (ServiceEndpointElement endpoint in appConfigService.Endpoints)
			{
				Console.WriteLine("{0}{1}", appConfigService.Host.BaseAddresses[0].BaseAddress, endpoint.Address.OriginalString);
			}

			Console.WriteLine(Environment.NewLine);
		}
예제 #10
0
 private void AddService(string serviceName)
 {
     if (serviceconfig.Services.ContainsKey(serviceName)) return;
     ServiceElement item = new ServiceElement();
     item.Name = serviceName;
     item.BehaviorConfiguration = serviceName + "_BehaviorConfiguration";
     serviceconfig.Services.Add(item);
 }
예제 #11
0
 /// <summary>
 /// Loads and configures a WCF service instance
 /// </summary>
 /// <param name="service">
 /// The service to load
 /// </param>
 /// <param name="assemblies">
 /// The list of assemblies to search for the
 /// WCF service class
 /// </param>
 /// <returns>
 /// The configured service host, if successful
 /// Null otherwise
 /// </returns>
 private WcfHost LoadService(ServiceElement service, IList<Assembly> assemblies)
 {
     // locate the type of the search assembly list
      Type serviceType = null;
      foreach (Assembly assembly in assemblies)
      {
     serviceType = assembly.GetType(service.Name, false);
     if (serviceType != null)
        break;
      }
      // create the service host for this service
      if (serviceType != null)
     return new WcfHost(serviceType, service);
      LogError(
     new TypeLoadException(
        String.Format(
           "The service type {0} was not found in the assembly search list\r\n{1}",
           service.Name,
           String.Join("\r\n", assemblies)
        )
     ),
     "Failed to initialize a the service instance {0}",
     service.Name
      );
      return null;
 }
예제 #12
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);
                }
            }
        }