System.ServiceModel.Configuration.StandardEndpointsSection.GetSection C# (CSharp) Метод

GetSection() публичный статический Метод

public static GetSection ( System config ) : StandardEndpointsSection
config System
Результат StandardEndpointsSection
		public static StandardEndpointsSection GetSection (System.Configuration.Configuration config) {
			ServiceModelSectionGroup sm = ServiceModelSectionGroup.GetSectionGroup (config);
			if (sm == null)
				throw new SystemException ("Could not retrieve configuration section group 'system.serviceModel'");
			if (sm.StandardEndpoints == null)
				throw new SystemException ("Could not retrieve configuration sub section group 'standardEndpoints' in 'system.serviceModel'");
			return sm.StandardEndpoints;
		}

Usage Example

Пример #1
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);
        }
StandardEndpointsSection