コード例 #1
0
        /// <summary>
        /// Creates a <see cref="DomainServiceEndpointFactory"/> from a <see cref="ProviderSettings"/> object.
        /// </summary>
        /// <param name="provider">The <see cref="ProviderSettings"/> object.</param>
        /// <returns>A <see cref="DomainServiceEndpointFactory"/>.</returns>
        private static DomainServiceEndpointFactory CreateEndpointFactoryInstance(ProviderSettings provider)
        {
            Type endpointFactoryType = Type.GetType(provider.Type, /* throwOnError */ true);
            DomainServiceEndpointFactory endpointFactory = (DomainServiceEndpointFactory)Activator.CreateInstance(endpointFactoryType);

            endpointFactory.Name       = provider.Name;
            endpointFactory.Parameters = provider.Parameters;
            return(endpointFactory);
        }
コード例 #2
0
        /// <summary>
        /// Creates a description of the service hosted.
        /// </summary>
        /// <param name="implementedContracts">
        /// The <see cref="IDictionary&lt;TKey,TValue&gt;"/> 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;
            }
        }
コード例 #3
0
        /// <summary>
        /// Creates a description of the service hosted.
        /// </summary>
        /// <param name="implementedContracts">
        /// The <see cref="IDictionary&lt;TKey,TValue&gt;"/> 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;
            }
        }