1 //------------------------------------------------------------------------------ 2 // Copyright (c) Microsoft Corporation. All rights reserved. 3 //------------------------------------------------------------------------------ 4 5 namespace System.ServiceModel.Configuration 6 { 7 using System.Collections.ObjectModel; 8 using System.Configuration; 9 using System.Runtime; 10 using System.Security; 11 using System.ServiceModel; 12 using System.ServiceModel.Channels; 13 14 public abstract partial class BindingCollectionElement : ConfigurationElement, IConfigurationContextProviderInternal 15 { 16 string bindingName = string.Empty; 17 GetDefault()18 protected internal abstract Binding GetDefault(); 19 20 public string BindingName 21 { 22 get 23 { 24 if (String.IsNullOrEmpty(this.bindingName)) 25 { 26 this.bindingName = this.GetBindingName(); 27 } 28 29 return this.bindingName; 30 } 31 } 32 33 public abstract Type BindingType 34 { 35 get; 36 } 37 38 public abstract ReadOnlyCollection<IBindingConfigurationElement> ConfiguredBindings 39 { 40 get; 41 } 42 ContainsKey(string name)43 public abstract bool ContainsKey(string name); 44 45 [Fx.Tag.SecurityNote(Critical = "Calls UnsafeLookupCollection which elevates.", 46 Safe = "Doesn't leak config objects.")] 47 [SecuritySafeCritical] GetBindingName()48 string GetBindingName() 49 { 50 string configuredSectionName = String.Empty; 51 ExtensionElementCollection collection = null; 52 Type extensionSectionType = this.GetType(); 53 54 collection = ExtensionsSection.UnsafeLookupCollection(ConfigurationStrings.BindingExtensions, ConfigurationHelpers.GetEvaluationContext(this)); 55 56 if (null == collection) 57 { 58 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.GetString(SR.ConfigExtensionCollectionNotFound, 59 ConfigurationStrings.BindingExtensions), 60 this.ElementInformation.Source, 61 this.ElementInformation.LineNumber)); 62 } 63 64 for (int i = 0; i < collection.Count; i++) 65 { 66 ExtensionElement collectionElement = collection[i]; 67 68 // Optimize for assembly qualified names. 69 if (collectionElement.Type.Equals(extensionSectionType.AssemblyQualifiedName, StringComparison.Ordinal)) 70 { 71 configuredSectionName = collectionElement.Name; 72 break; 73 } 74 75 // Check type directly for the case that the extension is registered with something less than 76 // an full assembly qualified name. 77 Type collectionElementType = Type.GetType(collectionElement.Type, false); 78 if (null != collectionElementType && extensionSectionType.Equals(collectionElementType)) 79 { 80 configuredSectionName = collectionElement.Name; 81 break; 82 } 83 } 84 85 if (String.IsNullOrEmpty(configuredSectionName)) 86 { 87 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.GetString(SR.ConfigExtensionTypeNotRegisteredInCollection, 88 extensionSectionType.AssemblyQualifiedName, 89 ConfigurationStrings.BindingExtensions), 90 this.ElementInformation.Source, 91 this.ElementInformation.LineNumber)); 92 } 93 94 return configuredSectionName; 95 } 96 TryAdd(string name, Binding binding, Configuration config)97 protected internal abstract bool TryAdd(string name, Binding binding, Configuration config); 98 IConfigurationContextProviderInternal.GetEvaluationContext()99 ContextInformation IConfigurationContextProviderInternal.GetEvaluationContext() 100 { 101 return this.EvaluationContext; 102 } 103 104 [Fx.Tag.SecurityNote(Miscellaneous = "RequiresReview - the return value will be used for a security decision -- see comment in interface definition.")] IConfigurationContextProviderInternal.GetOriginalEvaluationContext()105 ContextInformation IConfigurationContextProviderInternal.GetOriginalEvaluationContext() 106 { 107 Fx.Assert("Not implemented: IConfigurationContextProviderInternal.GetOriginalEvaluationContext"); 108 return null; 109 } 110 } 111 } 112 113 114 115