/// 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 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); }
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); }
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); }