상속: System.Configuration.ConfigurationElement, IConfigurationContextProviderInternal
예제 #1
0
        /// 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);
        }
        public static ServiceEndpoint ConfigureStandardEndpoint(ContractDescription cd, ServiceEndpointElement element)
        {
            string kind = element.Kind;
            string endpointConfiguration = element.EndpointConfiguration;

            EndpointCollectionElement section = ConfigUtil.StandardEndpointsSection [kind];

            if (section == null)
            {
                throw new ArgumentException(String.Format("standard endpoint section for '{0}' was not found.", kind));
            }

            StandardEndpointElement e = section.GetDefaultStandardEndpointElement();

            ServiceEndpoint inst = e.CreateServiceEndpoint(cd);

            foreach (StandardEndpointElement el in section.ConfiguredEndpoints)
            {
                if (el.Name == endpointConfiguration)
                {
                    el.InitializeAndValidate(element);
                    el.ApplyConfiguration(inst, element);
                    break;
                }
            }

            return(inst);
        }
예제 #3
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);
        }
예제 #4
0
 internal static void ValidateEndpointReference(string endpoint, string endpointConfiguration, ContextInformation evaluationContext, ConfigurationElement configurationElement)
 {
     if (evaluationContext == null)
     {
         DiagnosticUtility.FailFast("ValidateEndpointReference() should only called with valid ContextInformation");
     }
     if (!string.IsNullOrEmpty(endpoint))
     {
         EndpointCollectionElement element = null;
         if (evaluationContext != null)
         {
             element = ConfigurationHelpers.UnsafeGetAssociatedEndpointCollectionElement(evaluationContext, endpoint);
         }
         else
         {
             element = ConfigurationHelpers.UnsafeGetEndpointCollectionElement(endpoint);
         }
         if (element == null)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(System.ServiceModel.SR.GetString("ConfigInvalidSection", new object[] { ConfigurationHelpers.GetEndpointsSectionPath(endpoint) }), configurationElement.ElementInformation.Source, configurationElement.ElementInformation.LineNumber));
         }
         if (!string.IsNullOrEmpty(endpointConfiguration) && !element.ContainsKey(endpointConfiguration))
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(System.ServiceModel.SR.GetString("ConfigInvalidEndpointName", new object[] { endpointConfiguration, ConfigurationHelpers.GetEndpointsSectionPath(endpoint), "endpointConfiguration" }), configurationElement.ElementInformation.Source, configurationElement.ElementInformation.LineNumber));
         }
     }
 }
예제 #5
0
        internal static void ValidateEndpointReference(string endpoint, string endpointConfiguration, ContextInformation evaluationContext, ConfigurationElement configurationElement)
        {
            // ValidateEndpointReference built on assumption that evaluationContext 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 == evaluationContext)
            {
                Fx.Assert("ValidateEndpointReference() should only called with valid ContextInformation");
                DiagnosticUtility.FailFast("ValidateEndpointReference() should only called with valid ContextInformation");
            }

            if (!String.IsNullOrEmpty(endpoint))
            {
                EndpointCollectionElement endpointCollectionElement = null;

                if (null != evaluationContext)
                {
                    endpointCollectionElement = ConfigurationHelpers.UnsafeGetAssociatedEndpointCollectionElement(evaluationContext, endpoint);
                }
                else
                {
                    endpointCollectionElement = ConfigurationHelpers.UnsafeGetEndpointCollectionElement(endpoint);
                }

                if (endpointCollectionElement == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.GetString(SR.ConfigInvalidSection,
                                                                                                                            ConfigurationHelpers.GetEndpointsSectionPath(endpoint)),
                                                                                                               configurationElement.ElementInformation.Source,
                                                                                                               configurationElement.ElementInformation.LineNumber));
                }

                if (!String.IsNullOrEmpty(endpointConfiguration))
                {
                    if (!endpointCollectionElement.ContainsKey(endpointConfiguration))
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.GetString(SR.ConfigInvalidEndpointName,
                                                                                                                                endpointConfiguration,
                                                                                                                                ConfigurationHelpers.GetEndpointsSectionPath(endpoint),
                                                                                                                                ConfigurationStrings.EndpointConfiguration),
                                                                                                                   configurationElement.ElementInformation.Source,
                                                                                                                   configurationElement.ElementInformation.LineNumber));
                    }
                }
            }
        }
예제 #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);
        }