/// <summary> /// Creates a description of the service hosted. /// </summary> /// <param name="implementedContracts"> /// The <see cref="IDictionary<TKey,TValue>"/> with key pairs of /// type (string, <see cref="ContractDescription"/>) that contains the /// keyed-contracts of the hosted service that have been implemented. /// </param> /// <returns>A <see cref="ServiceDescription"/> of the hosted service.</returns> protected override ServiceDescription CreateDescription(out IDictionary <string, ContractDescription> implementedContracts) { try { Type domainServiceType = this._domainServiceDescription.DomainServiceType; ServiceDescription serviceDesc = ServiceDescription.GetService(domainServiceType); implementedContracts = new Dictionary <string, ContractDescription>(); DomainServicesSection config = (DomainServicesSection)WebConfigurationManager.GetSection("system.serviceModel/domainServices"); if (config == null) { // Make sure we have a config instance, as that's where we put our default configuration. If we don't do this, our // binary endpoint won't be used when someone doesn't have a <domainServices/> section in their web.config. config = new DomainServicesSection(); config.InitializeDefaultInternal(); } foreach (ProviderSettings provider in config.Endpoints) { DomainServiceEndpointFactory endpointFactory = DomainServiceHost.CreateEndpointFactoryInstance(provider); foreach (ServiceEndpoint endpoint in endpointFactory.CreateEndpoints(this._domainServiceDescription, this)) { string contractName = endpoint.Contract.ConfigurationName; ContractDescription contract; if (implementedContracts.TryGetValue(contractName, out contract) && contract != endpoint.Contract) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resource.DomainServiceHost_DuplicateContractName, contract.ConfigurationName)); } // Register the contract. implementedContracts[endpoint.Contract.ConfigurationName] = endpoint.Contract; // Register the endpoint. serviceDesc.Endpoints.Add(endpoint); } } return(serviceDesc); } catch (Exception ex) { DiagnosticUtility.ServiceException(ex); throw; } }
/// <summary> /// Creates a description of the service hosted. /// </summary> /// <param name="implementedContracts"> /// The <see cref="IDictionary<TKey,TValue>"/> with key pairs of /// type (string, <see cref="ContractDescription"/>) that contains the /// keyed-contracts of the hosted service that have been implemented. /// </param> /// <returns>A <see cref="ServiceDescription"/> of the hosted service.</returns> protected override ServiceDescription CreateDescription(out IDictionary <string, ContractDescription> implementedContracts) { try { Type domainServiceType = this._domainServiceDescription.DomainServiceType; ServiceDescription serviceDesc = ServiceDescription.GetService(domainServiceType); implementedContracts = new Dictionary <string, ContractDescription>(); DomainServicesSection config = DomainServicesSection.Current; foreach (ProviderSettings provider in config.Endpoints) { DomainServiceEndpointFactory endpointFactory = DomainServiceHost.CreateEndpointFactoryInstance(provider); foreach (ServiceEndpoint endpoint in endpointFactory.CreateEndpoints(this._domainServiceDescription, this)) { string contractName = endpoint.Contract.ConfigurationName; ContractDescription contract; if (implementedContracts.TryGetValue(contractName, out contract) && contract != endpoint.Contract) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resource.DomainServiceHost_DuplicateContractName, contract.ConfigurationName)); } // Register the contract. implementedContracts[endpoint.Contract.ConfigurationName] = endpoint.Contract; // Register the endpoint. serviceDesc.Endpoints.Add(endpoint); } } return(serviceDesc); } catch (Exception ex) { DiagnosticUtility.ServiceException(ex); throw; } }
/// <summary> /// Creates a description of the service hosted. /// </summary> /// <param name="implementedContracts"> /// The <see cref="IDictionary<TKey,TValue>"/> with key pairs of /// type (string, <see cref="ContractDescription"/>) that contains the /// keyed-contracts of the hosted service that have been implemented. /// </param> /// <returns>A <see cref="ServiceDescription"/> of the hosted service.</returns> protected override ServiceDescription CreateDescription(out IDictionary<string, ContractDescription> implementedContracts) { try { Type domainServiceType = this._domainServiceDescription.DomainServiceType; ServiceDescription serviceDesc = ServiceDescription.GetService(domainServiceType); implementedContracts = new Dictionary<string, ContractDescription>(); DomainServicesSection config = (DomainServicesSection)WebConfigurationManager.GetSection("system.serviceModel/domainServices"); if (config == null) { // Make sure we have a config instance, as that's where we put our default configuration. If we don't do this, our // binary endpoint won't be used when someone doesn't have a <domainServices/> section in their web.config. config = new DomainServicesSection(); config.InitializeDefaultInternal(); } foreach (ProviderSettings provider in config.Endpoints) { DomainServiceEndpointFactory endpointFactory = DomainServiceHost.CreateEndpointFactoryInstance(provider); foreach (ServiceEndpoint endpoint in endpointFactory.CreateEndpoints(this._domainServiceDescription, this)) { string contractName = endpoint.Contract.ConfigurationName; ContractDescription contract; if (implementedContracts.TryGetValue(contractName, out contract) && contract != endpoint.Contract) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resource.DomainServiceHost_DuplicateContractName, contract.ConfigurationName)); } // Register the contract. implementedContracts[endpoint.Contract.ConfigurationName] = endpoint.Contract; // Register the endpoint. serviceDesc.Endpoints.Add(endpoint); } } return serviceDesc; } catch (Exception ex) { DiagnosticUtility.ServiceException(ex); throw; } }
/// <summary> /// Returns the <see cref="DomainServicesSection"/> for the "system.serviceModel/domainServices" /// section. If it does not exist, a new default one will be created. /// </summary> /// <param name="created">Output parameter that is set to <c>true</c> if the section did not exist and was created here.</param> /// <returns>A new or existing <see cref="DomainServicesSection"/>.</returns> public DomainServicesSection GetOrCreateDomainServicesSection(out bool created) { created = false; DomainServicesSection domainServicesSection = this._configuration.GetSection(DomainServicesFullSectionName) as DomainServicesSection; if (domainServicesSection == null) { ServiceModelSectionGroup serviceModelSectionGroup = this.GetOrCreateServiceModelSectionGroup(); domainServicesSection = this._configuration.GetSection(DomainServicesFullSectionName) as DomainServicesSection; if (domainServicesSection == null) { domainServicesSection = new DomainServicesSection(); domainServicesSection.SectionInformation.AllowDefinition = ConfigurationAllowDefinition.MachineToApplication; domainServicesSection.SectionInformation.RequirePermission = false; serviceModelSectionGroup.Sections.Add(DomainServicesSectionName, domainServicesSection); created = true; } } return domainServicesSection; }