EndpointCollectionElement.cs 4.4 KB

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