Beispiel #1
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);
        }
Beispiel #2
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);
        }