/// Be sure to update UnsafeGetAssociatedBindingCollectionElement if you modify this method internal static BindingCollectionElement GetAssociatedBindingCollectionElement(ContextInformation evaluationContext, string bindingCollectionName) { BindingCollectionElement retVal = null; BindingsSection bindingsSection = (BindingsSection)ConfigurationHelpers.GetAssociatedSection(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); }
/// 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); }
internal static ExtensionElementCollection LookupCollection(string collectionName, ContextInformation evaluationContext) { ExtensionsSection associatedSection = null; if (evaluationContext != null) { associatedSection = (ExtensionsSection)ConfigurationHelpers.GetAssociatedSection(evaluationContext, ConfigurationStrings.ExtensionsSectionPath); } else { if (DiagnosticUtility.ShouldTraceWarning) { TraceUtility.TraceEvent(TraceEventType.Warning, 0x80018, System.ServiceModel.SR.GetString("TraceCodeEvaluationContextNotFound"), null, (Exception)null); } associatedSection = (ExtensionsSection)ConfigurationHelpers.GetSection(ConfigurationStrings.ExtensionsSectionPath); } switch (collectionName) { case "behaviorExtensions": return(associatedSection.BehaviorExtensions); case "bindingElementExtensions": return(associatedSection.BindingElementExtensions); case "bindingExtensions": return(associatedSection.BindingExtensions); case "endpointExtensions": return(associatedSection.EndpointExtensions); } DiagnosticUtility.FailFast(string.Format(CultureInfo.InvariantCulture, "{0} is not a valid ServiceModelExtensionsSection collection name.", new object[] { collectionName })); return(null); }
/// Be sure to update UnsafeLookupCollection if you modify this method internal static ExtensionElementCollection LookupCollection(string collectionName, ContextInformation evaluationContext) { ExtensionElementCollection collection = null; ExtensionsSection extensionsSection = null; if (null != evaluationContext) { extensionsSection = (ExtensionsSection)ConfigurationHelpers.GetAssociatedSection(evaluationContext, ConfigurationStrings.ExtensionsSectionPath); } else { if (DiagnosticUtility.ShouldTraceWarning) { TraceUtility.TraceEvent(TraceEventType.Warning, TraceCode.EvaluationContextNotFound, SR.GetString(SR.TraceCodeEvaluationContextNotFound), null, (Exception)null); } extensionsSection = (ExtensionsSection)ConfigurationHelpers.GetSection(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); }