internal static EndpointCollectionElement UnsafeGetAssociatedEndpointCollectionElement(ContextInformation evaluationContext, string endpointCollectionName)
        {
            EndpointCollectionElement retVal           = null;
            StandardEndpointsSection  endpointsSection = (StandardEndpointsSection)ConfigurationHelpers.UnsafeGetAssociatedSection(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);
        }
        internal static BindingCollectionElement UnsafeGetAssociatedBindingCollectionElement(ContextInformation evaluationContext, string bindingCollectionName)
        {
            BindingCollectionElement retVal          = null;
            BindingsSection          bindingsSection = (BindingsSection)ConfigurationHelpers.UnsafeGetAssociatedSection(evaluationContext, ConfigurationStrings.BindingsSectionGroupPath);

            if (null != bindingsSection)
            {
                bindingsSection.UpdateBindingSections(evaluationContext);
                try
                {
                    retVal = bindingsSection[bindingCollectionName];
                }
                catch (KeyNotFoundException)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                              new ConfigurationErrorsException(SR.GetString(SR.ConfigBindingExtensionNotFound,
                                                                            ConfigurationHelpers.GetBindingsSectionPath(bindingCollectionName))));
                }
                catch (NullReferenceException) // System.Configuration.ConfigurationElement
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                              new ConfigurationErrorsException(SR.GetString(SR.ConfigBindingExtensionNotFound,
                                                                            ConfigurationHelpers.GetBindingsSectionPath(bindingCollectionName))));
                }
            }

            return(retVal);
        }
Esempio n. 3
0
        internal static void ValidateServiceBehaviorReference(string behaviorConfiguration, ContextInformation evaluationContext, ConfigurationElement configurationElement)
        {
            // ValidateBehaviorReference 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("ValidateBehaviorReference() should only called with valid ContextInformation");
                DiagnosticUtility.FailFast("ValidateBehaviorReference() should only called with valid ContextInformation");
            }

#if DESKTOP
            if (!String.IsNullOrEmpty(behaviorConfiguration))
            {
                BehaviorsSection behaviors = (BehaviorsSection)ConfigurationHelpers.UnsafeGetAssociatedSection(evaluationContext, ConfigurationStrings.BehaviorsSectionPath);
                if (!behaviors.ServiceBehaviors.ContainsKey(behaviorConfiguration))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.GetString(SR.ConfigInvalidServiceBehavior,
                                                                                                                            behaviorConfiguration),
                                                                                                               configurationElement.ElementInformation.Source,
                                                                                                               configurationElement.ElementInformation.LineNumber));
                }
            }
#endif
        }
        internal static ExtensionElementCollection UnsafeLookupCollection(string collectionName, ContextInformation evaluationContext)
        {
            ExtensionsSection section = null;

            if (evaluationContext != null)
            {
                section = (ExtensionsSection)ConfigurationHelpers.UnsafeGetAssociatedSection(evaluationContext, ConfigurationStrings.ExtensionsSectionPath);
            }
            else
            {
                if (DiagnosticUtility.ShouldTraceWarning)
                {
                    TraceUtility.TraceEvent(TraceEventType.Warning, 0x80018, System.ServiceModel.SR.GetString("TraceCodeEvaluationContextNotFound"), null, (Exception)null);
                }
                section = (ExtensionsSection)ConfigurationHelpers.UnsafeGetSection(ConfigurationStrings.ExtensionsSectionPath);
            }
            switch (collectionName)
            {
            case "behaviorExtensions":
                return(section.BehaviorExtensions);

            case "bindingElementExtensions":
                return(section.BindingElementExtensions);

            case "bindingExtensions":
                return(section.BindingExtensions);

            case "endpointExtensions":
                return(section.EndpointExtensions);
            }
            DiagnosticUtility.FailFast(string.Format(CultureInfo.InvariantCulture, "{0} is not a valid ServiceModelExtensionsSection collection name.", new object[] { collectionName }));
            return(null);
        }
        internal static ExtensionElementCollection UnsafeLookupCollection(string collectionName, ContextInformation evaluationContext)
        {
            ExtensionElementCollection collection        = null;
            ExtensionsSection          extensionsSection = null;

            if (null != evaluationContext)
            {
                extensionsSection = (ExtensionsSection)ConfigurationHelpers.UnsafeGetAssociatedSection(evaluationContext, ConfigurationStrings.ExtensionsSectionPath);
            }
            else
            {
                if (DiagnosticUtility.ShouldTraceWarning)
                {
                    TraceUtility.TraceEvent(TraceEventType.Warning,
                                            TraceCode.EvaluationContextNotFound,
                                            SR.GetString(SR.TraceCodeEvaluationContextNotFound),
                                            null,
                                            (Exception)null);
                }

                extensionsSection = (ExtensionsSection)ConfigurationHelpers.UnsafeGetSection(ConfigurationStrings.ExtensionsSectionPath);
            }

            switch (collectionName)
            {
            case (ConfigurationStrings.BehaviorExtensions):
                collection = extensionsSection.BehaviorExtensions;
                break;

            case (ConfigurationStrings.BindingElementExtensions):
                collection = extensionsSection.BindingElementExtensions;
                break;

            case (ConfigurationStrings.BindingExtensions):
                collection = extensionsSection.BindingExtensions;
                break;

            case (ConfigurationStrings.EndpointExtensions):
                collection = extensionsSection.EndpointExtensions;
                break;

            default:
                // LookupCollection built on assumption that collectionName 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.
                Fx.Assert(String.Format(CultureInfo.InvariantCulture, "{0} is not a valid ServiceModelExtensionsSection collection name.", collectionName));
                DiagnosticUtility.FailFast(String.Format(CultureInfo.InvariantCulture, "{0} is not a valid ServiceModelExtensionsSection collection name.", collectionName));
                break;
            }

            return(collection);
        }
 internal static void ValidateServiceBehaviorReference(string behaviorConfiguration, ContextInformation evaluationContext, ConfigurationElement configurationElement)
 {
     if (evaluationContext == null)
     {
         DiagnosticUtility.FailFast("ValidateBehaviorReference() should only called with valid ContextInformation");
     }
     if (!string.IsNullOrEmpty(behaviorConfiguration))
     {
         BehaviorsSection section = (BehaviorsSection)ConfigurationHelpers.UnsafeGetAssociatedSection(evaluationContext, ConfigurationStrings.BehaviorsSectionPath);
         if (!section.ServiceBehaviors.ContainsKey(behaviorConfiguration))
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(System.ServiceModel.SR.GetString("ConfigInvalidServiceBehavior", new object[] { behaviorConfiguration }), configurationElement.ElementInformation.Source, configurationElement.ElementInformation.LineNumber));
         }
     }
 }
 internal static CommonBehaviorsSection UnsafeGetAssociatedSection(ContextInformation contextEval)
 {
     return((CommonBehaviorsSection)ConfigurationHelpers.UnsafeGetAssociatedSection(contextEval, ConfigurationStrings.CommonBehaviorsSectionPath));
 }
Esempio n. 8
0
 internal static BehaviorsSection UnsafeGetAssociatedSection(ContextInformation evalContext)
 {
     return((BehaviorsSection)ConfigurationHelpers.UnsafeGetAssociatedSection(evalContext, ConfigurationStrings.BehaviorsSectionPath));
 }