public static ServiceModelSectionGroup GetSectionGroup( ConfigurationType config) { ServiceModelSectionGroup ret = (ServiceModelSectionGroup)config.GetSectionGroup("system.serviceModel"); if (ret == null) { throw new SystemException("Internal configuration error: section 'system.serviceModel' was not found."); } return(ret); }
protected internal override bool TryAdd(string name, Binding binding, Configuration config) { if (String.IsNullOrEmpty(name)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("name"); } if (null == binding) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("binding"); } if (null == config) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("config"); } ServiceModelSectionGroup sg = ServiceModelSectionGroup.GetSectionGroup(config); CustomBindingElementCollection customBindings = sg.Bindings.CustomBinding.Bindings; CustomBindingElement configElement = new CustomBindingElement(name); customBindings.Add(configElement); ExtensionElementCollection collection = sg.Extensions.BindingElementExtensions; CustomBinding customBinding = (CustomBinding)binding; foreach (BindingElement bindingElement in customBinding.Elements) { BindingElementExtensionElement bindingElementExtension; bool foundMatch = TryCreateMatchingExtension(bindingElement, collection, false, configElement.CollectionElementBaseType.AssemblyQualifiedName, out bindingElementExtension); if (!foundMatch) { foundMatch = TryCreateMatchingExtension(bindingElement, collection, true, configElement.CollectionElementBaseType.AssemblyQualifiedName, out bindingElementExtension); } if (!foundMatch) { break; } bindingElementExtension.InitializeFrom(bindingElement); configElement.Add(bindingElementExtension); } bool retval = configElement.Count == customBinding.Elements.Count; if (!retval) { customBindings.Remove(configElement); } return(retval); }
public static BindingsSection 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.Bindings == null) { throw new SystemException("Could not retrieve configuration sub section group 'bindings' in 'system.serviceModel'"); } return(sm.Bindings); }
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); }
protected internal override bool TryAdd(string name, Binding binding, System.Configuration.Configuration config) { if (string.IsNullOrEmpty(name)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("name"); } if (binding == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("binding"); } if (config == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("config"); } ServiceModelSectionGroup sectionGroup = ServiceModelSectionGroup.GetSectionGroup(config); CustomBindingElementCollection bindings = sectionGroup.Bindings.CustomBinding.Bindings; CustomBindingElement element = new CustomBindingElement(name); bindings.Add(element); ExtensionElementCollection bindingElementExtensions = sectionGroup.Extensions.BindingElementExtensions; CustomBinding binding2 = (CustomBinding)binding; foreach (BindingElement element2 in binding2.Elements) { BindingElementExtensionElement element3; bool flag = this.TryCreateMatchingExtension(element2, bindingElementExtensions, false, element.CollectionElementBaseType.AssemblyQualifiedName, out element3); if (!flag) { flag = this.TryCreateMatchingExtension(element2, bindingElementExtensions, true, element.CollectionElementBaseType.AssemblyQualifiedName, out element3); } if (!flag) { break; } element3.InitializeFrom(element2); element.Add(element3); } bool flag2 = element.Count == binding2.Elements.Count; if (!flag2) { bindings.Remove(element); } return(flag2); }
/// <summary> /// Initialises an instance of a service endpoint from the provided configuration context. /// </summary> /// <param name="configurationName">The name property in an endpoint configuration element.</param> /// <param name="context">Configuration context used to read settings from.</param> /// <returns>An instance of a service endpoint initialised with the provided configuration settings.</returns> private ServiceEndpoint LoadServiceEndPoint(string configurationName, ServiceModelSectionGroup context) { CustomConfigurationChannelFactory<object>.ConfigurationLoader loader = new CustomConfigurationChannelFactory<object>.ConfigurationLoader(context); return loader.LoadChannelBehaviors(this.CreateServiceEndpoint(), configurationName); }
/// <summary> /// Gets the binding. /// </summary> /// <param name="bindingName">Name of the binding.</param> /// <param name="bindingType">Type of the binding.</param> /// <param name="serviceModelSection">The service model section.</param> /// <returns>Binding.</returns> /// <exception cref="System.InvalidOperationException"> /// Service binding not found. /// or /// Binding configuration not found. /// </exception> private static Binding GetBinding(string bindingName, string bindingType, ServiceModelSectionGroup serviceModelSection) { if (serviceModelSection.Bindings == null) throw new InvalidOperationException("Service binding not found."); foreach (var bce in serviceModelSection.Bindings.BindingCollections.Where(bc => bc != null)) { foreach (var bindingConfiguration in bce.ConfiguredBindings.Where(b => b != null)) { if (bce.BindingName == bindingType && bindingConfiguration.Name == bindingName) { var binding = (Binding)Activator.CreateInstance(bce.BindingType); bindingConfiguration.ApplyConfiguration(binding); binding.Name = bindingConfiguration.Name; return binding; } } } throw new InvalidOperationException("Binding configuration not found."); }
/// <summary> /// Adds the behaviors. /// </summary> /// <param name="behaviorConfiguration">The behavior configuration.</param> /// <param name="serviceEndpoint">The service endpoint.</param> /// <param name="group">The group.</param> private static void AddBehaviors(string behaviorConfiguration, ServiceEndpoint serviceEndpoint, ServiceModelSectionGroup group) { var behaviorElement = group.Behaviors.EndpointBehaviors[behaviorConfiguration]; foreach (var behaviorExtension in behaviorElement) { var extension = behaviorExtension.GetType() .InvokeMember( "CreateBehavior", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Instance, null, behaviorExtension, null, CultureInfo.InvariantCulture); if (extension != null) serviceEndpoint.Behaviors.Add((IEndpointBehavior)extension); } }
/// <summary> /// Returns the <see cref="ServiceModelSectionGroup"/> for the "system.serviceModel" /// section group. If it does not exist, a new default one will be created. /// </summary> /// <returns>A new or existing <see cref="ServiceModelSectionGroup"/></returns> public ServiceModelSectionGroup GetOrCreateServiceModelSectionGroup() { ServiceModelSectionGroup serviceModelSectionGroup = this._configuration.GetSectionGroup(SystemServiceModelSectionName) as ServiceModelSectionGroup; if (serviceModelSectionGroup == null) { serviceModelSectionGroup = new ServiceModelSectionGroup(); this._configuration.SectionGroups.Add(SystemServiceModelSectionName, serviceModelSectionGroup); } return serviceModelSectionGroup; }