Inheritance: System.Configuration.ConfigurationSection
示例#1
0
        private void ValidateSection()
        {
            ContextInformation evaluationContext = ConfigurationHelpers.GetEvaluationContext(this);

            if (evaluationContext != null)
            {
                foreach (ChannelEndpointElement element in this.Endpoints)
                {
                    if (string.IsNullOrEmpty(element.Kind))
                    {
                        if (!string.IsNullOrEmpty(element.EndpointConfiguration))
                        {
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(System.ServiceModel.SR.GetString("ConfigInvalidAttribute", new object[] { "endpointConfiguration", "endpoint", "kind" })));
                        }
                        if (string.IsNullOrEmpty(element.Binding))
                        {
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(System.ServiceModel.SR.GetString("RequiredAttributeMissing", new object[] { "binding", "endpoint" })));
                        }
                        if (string.IsNullOrEmpty(element.Contract))
                        {
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(System.ServiceModel.SR.GetString("RequiredAttributeMissing", new object[] { "contract", "endpoint" })));
                        }
                    }
                    if (string.IsNullOrEmpty(element.Binding) && !string.IsNullOrEmpty(element.BindingConfiguration))
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(System.ServiceModel.SR.GetString("ConfigInvalidAttribute", new object[] { "bindingConfiguration", "endpoint", "binding" })));
                    }
                    BehaviorsSection.ValidateEndpointBehaviorReference(element.BehaviorConfiguration, evaluationContext, element);
                    BindingsSection.ValidateBindingReference(element.Binding, element.BindingConfiguration, evaluationContext, element);
                    StandardEndpointsSection.ValidateEndpointReference(element.Kind, element.EndpointConfiguration, evaluationContext, element);
                }
            }
        }
        /// Be sure to update UnsafeGetAssociatedEndpointCollectionElement if you modify this method
        internal static EndpointCollectionElement GetAssociatedEndpointCollectionElement(ContextInformation evaluationContext, string endpointCollectionName)
        {
            EndpointCollectionElement retVal           = null;
            StandardEndpointsSection  endpointsSection = (StandardEndpointsSection)ConfigurationHelpers.GetAssociatedSection(evaluationContext, ConfigurationStrings.StandardEndpointsSectionPath);

            if (null != endpointsSection)
            {
                endpointsSection.UpdateEndpointSections(evaluationContext);
                try
                {
                    retVal = (EndpointCollectionElement)endpointsSection[endpointCollectionName];
                }
                catch (KeyNotFoundException)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                              new ConfigurationErrorsException(SR.GetString(SR.ConfigEndpointExtensionNotFound,
                                                                            ConfigurationHelpers.GetEndpointsSectionPath(endpointCollectionName))));
                }
                catch (NullReferenceException) // System.Configuration.ConfigurationElement
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                              new ConfigurationErrorsException(SR.GetString(SR.ConfigEndpointExtensionNotFound,
                                                                            ConfigurationHelpers.GetEndpointsSectionPath(endpointCollectionName))));
                }
            }

            return(retVal);
        }
        void ValidateSection()
        {
            ContextInformation context = ConfigurationHelpers.GetEvaluationContext(this);

            if (context != null)
            {
                foreach (ServiceElement service in this.Services)
                {
                    BehaviorsSection.ValidateServiceBehaviorReference(service.BehaviorConfiguration, context, service);

                    foreach (ServiceEndpointElement endpoint in service.Endpoints)
                    {
                        if (string.IsNullOrEmpty(endpoint.Kind))
                        {
                            if (!string.IsNullOrEmpty(endpoint.EndpointConfiguration))
                            {
                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.GetString(SR.ConfigInvalidAttribute, "endpointConfiguration", "endpoint", "kind")));
                            }
                            if (string.IsNullOrEmpty(endpoint.Binding))
                            {
                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.GetString(SR.RequiredAttributeMissing, "binding", "endpoint")));
                            }
                        }
                        if (string.IsNullOrEmpty(endpoint.Binding) && !string.IsNullOrEmpty(endpoint.BindingConfiguration))
                        {
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.GetString(SR.ConfigInvalidAttribute, "bindingConfiguration", "endpoint", "binding")));
                        }
                        BehaviorsSection.ValidateEndpointBehaviorReference(endpoint.BehaviorConfiguration, context, endpoint);
                        BindingsSection.ValidateBindingReference(endpoint.Binding, endpoint.BindingConfiguration, context, endpoint);
                        StandardEndpointsSection.ValidateEndpointReference(endpoint.Kind, endpoint.EndpointConfiguration, context, endpoint);
                    }
                }
            }
        }
示例#4
0
        internal static bool TryAdd(string name, ServiceEndpoint endpoint, out string endpointSectionName)
        {
            if (Configuration == null)
            {
                DiagnosticUtility.FailFast("The TryAdd(string name, ServiceEndpoint endpoint, Configuration config, out string endpointSectionName) variant of this function should always be called first. The Configuration object is not set.");
            }
            bool   flag = false;
            string str  = null;
            StandardEndpointsSection section = GetSection(Configuration);

            section.UpdateEndpointSections();
            foreach (string str2 in section.EndpointCollectionElements.Keys)
            {
                EndpointCollectionElement element = section.EndpointCollectionElements[str2];
                MethodInfo method = element.GetType().GetMethod("TryAdd", BindingFlags.NonPublic | BindingFlags.Instance);
                if (method != null)
                {
                    flag = (bool)method.Invoke(element, new object[] { name, endpoint, Configuration });
                    if (flag)
                    {
                        str = str2;
                        break;
                    }
                }
            }
            endpointSectionName = str;
            return(flag);
        }
示例#5
0
        internal static bool TryAdd(string name, ServiceEndpoint endpoint, Configuration config, out string endpointSectionName)
        {
            bool retval = false;

            StandardEndpointsSection.Configuration = config;
            try
            {
                retval = StandardEndpointsSection.TryAdd(name, endpoint, out endpointSectionName);
            }
            finally
            {
                StandardEndpointsSection.Configuration = null;
            }
            return(retval);
        }
示例#6
0
        internal static bool TryAdd(string name, ServiceEndpoint endpoint, out string endpointSectionName)
        {
            // TryAdd built on assumption that StandardEndpointsSectionGroup.Configuration is valid.
            // This should be protected at the callers site.  If assumption is invalid, then
            // configuration system is in an indeterminate state.  Need to stop in a manner that
            // user code can not capture.
            if (null == StandardEndpointsSection.Configuration)
            {
                Fx.Assert("The TryAdd(string name, ServiceEndpoint endpoint, Configuration config, out string endpointSectionName) variant of this function should always be called first. The Configuration object is not set.");
                DiagnosticUtility.FailFast("The TryAdd(string name, ServiceEndpoint endpoint, Configuration config, out string endpointSectionName) variant of this function should always be called first. The Configuration object is not set.");
            }

            bool   retval = false;
            string outEndpointSectionName         = null;
            StandardEndpointsSection sectionGroup = StandardEndpointsSection.GetSection(StandardEndpointsSection.Configuration);

            sectionGroup.UpdateEndpointSections();
            foreach (string sectionName in sectionGroup.EndpointCollectionElements.Keys)
            {
                EndpointCollectionElement endpointCollectionElement = sectionGroup.EndpointCollectionElements[sectionName];

                MethodInfo tryAddMethod = endpointCollectionElement.GetType().GetMethod("TryAdd", BindingFlags.Instance | BindingFlags.NonPublic);
                if (tryAddMethod != null)
                {
                    retval = (bool)tryAddMethod.Invoke(endpointCollectionElement, new object[] { name, endpoint, StandardEndpointsSection.Configuration });
                    if (retval)
                    {
                        outEndpointSectionName = sectionName;
                        break;
                    }
                }
            }

            // This little oddity exists to make sure that the out param is assigned to before the method
            // exits.
            endpointSectionName = outEndpointSectionName;
            return(retval);
        }
示例#7
0
        internal static EndpointCollectionElement GetAssociatedEndpointCollectionElement(ContextInformation evaluationContext, string endpointCollectionName)
        {
            EndpointCollectionElement element           = null;
            StandardEndpointsSection  associatedSection = (StandardEndpointsSection)GetAssociatedSection(evaluationContext, ConfigurationStrings.StandardEndpointsSectionPath);

            if (associatedSection != null)
            {
                associatedSection.UpdateEndpointSections(evaluationContext);
                try
                {
                    element = associatedSection[endpointCollectionName];
                }
                catch (KeyNotFoundException)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(System.ServiceModel.SR.GetString("ConfigEndpointExtensionNotFound", new object[] { GetEndpointsSectionPath(endpointCollectionName) })));
                }
                catch (NullReferenceException)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(System.ServiceModel.SR.GetString("ConfigEndpointExtensionNotFound", new object[] { GetEndpointsSectionPath(endpointCollectionName) })));
                }
            }
            return(element);
        }