StandardEndpointElement.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. //------------------------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------------------------
  4. namespace System.ServiceModel.Configuration
  5. {
  6. using System;
  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 StandardEndpointElement : ConfigurationElement, IConfigurationContextProviderInternal
  13. {
  14. [Fx.Tag.SecurityNote(Critical = "Stores information used in a security decision.")]
  15. [SecurityCritical]
  16. EvaluationContextHelper contextHelper;
  17. protected StandardEndpointElement()
  18. : base()
  19. {
  20. }
  21. protected internal abstract Type EndpointType
  22. {
  23. get;
  24. }
  25. [ConfigurationProperty(ConfigurationStrings.Name, Options = ConfigurationPropertyOptions.IsKey)]
  26. [StringValidator(MinLength = 0)]
  27. public string Name
  28. {
  29. get { return (string)base[ConfigurationStrings.Name]; }
  30. set
  31. {
  32. if (String.IsNullOrEmpty(value))
  33. {
  34. value = String.Empty;
  35. }
  36. base[ConfigurationStrings.Name] = value;
  37. }
  38. }
  39. public void InitializeAndValidate(ChannelEndpointElement channelEndpointElement)
  40. {
  41. if (null == channelEndpointElement)
  42. {
  43. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("channelEndpointElement");
  44. }
  45. // The properties channelEndpointElement.Name and this.Name are actually two different things:
  46. // - channelEndpointElement.Name corresponds to the service endpoint name
  47. // - this.Name is a token used as a key in the endpoint collection to identify
  48. // a specific bucket of configuration settings.
  49. // Thus, the Name property is skipped here.
  50. this.OnInitializeAndValidate(channelEndpointElement);
  51. }
  52. public void InitializeAndValidate(ServiceEndpointElement serviceEndpointElement)
  53. {
  54. if (null == serviceEndpointElement)
  55. {
  56. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("serviceEndpointElement");
  57. }
  58. // The properties serviceEndpointElement.Name and this.Name are actually two different things:
  59. // - serviceEndpointElement.Name corresponds to the service endpoint name
  60. // - this.Name is a token used as a key in the endpoint collection to identify
  61. // a specific bucket of configuration settings.
  62. // Thus, the Name property is skipped here.
  63. this.OnInitializeAndValidate(serviceEndpointElement);
  64. }
  65. public void ApplyConfiguration(ServiceEndpoint endpoint, ChannelEndpointElement channelEndpointElement)
  66. {
  67. if (null == endpoint)
  68. {
  69. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("endpoint");
  70. }
  71. if (null == channelEndpointElement)
  72. {
  73. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("channelEndpointElement");
  74. }
  75. if (endpoint.GetType() != this.EndpointType)
  76. {
  77. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.GetString(SR.ConfigInvalidTypeForEndpoint,
  78. this.EndpointType.AssemblyQualifiedName,
  79. endpoint.GetType().AssemblyQualifiedName));
  80. }
  81. // The properties endpoint.Name and this.Name are actually two different things:
  82. // - endpoint.Name corresponds to the service endpoint name and is surfaced through
  83. // serviceEndpointElement.Name
  84. // - this.Name is a token used as a key in the endpoint collection to identify
  85. // a specific bucket of configuration settings.
  86. // Thus, the Name property is skipped here.
  87. this.OnApplyConfiguration(endpoint, channelEndpointElement);
  88. }
  89. public void ApplyConfiguration(ServiceEndpoint endpoint, ServiceEndpointElement serviceEndpointElement)
  90. {
  91. if (null == endpoint)
  92. {
  93. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("endpoint");
  94. }
  95. if (null == serviceEndpointElement)
  96. {
  97. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("serviceEndpointElement");
  98. }
  99. if (endpoint.GetType() != this.EndpointType)
  100. {
  101. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.GetString(SR.ConfigInvalidTypeForEndpoint,
  102. (this.EndpointType == null) ? string.Empty : this.EndpointType.AssemblyQualifiedName,
  103. endpoint.GetType().AssemblyQualifiedName));
  104. }
  105. // The properties endpoint.Name and this.Name are actually two different things:
  106. // - endpoint.Name corresponds to the service endpoint name and is surfaced through
  107. // serviceEndpointElement.Name
  108. // - this.Name is a token used as a key in the endpoint collection to identify
  109. // a specific bucket of configuration settings.
  110. // Thus, the Name property is skipped here.
  111. this.OnApplyConfiguration(endpoint, serviceEndpointElement);
  112. }
  113. protected virtual internal void InitializeFrom(ServiceEndpoint endpoint)
  114. {
  115. if (null == endpoint)
  116. {
  117. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("endpoint");
  118. }
  119. if (endpoint.GetType() != this.EndpointType)
  120. {
  121. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.GetString(SR.ConfigInvalidTypeForEndpoint,
  122. (this.EndpointType == null) ? string.Empty : this.EndpointType.AssemblyQualifiedName,
  123. endpoint.GetType().AssemblyQualifiedName));
  124. }
  125. // The properties endpoint.Name and this.Name are actually two different things:
  126. // - endpoint.Name corresponds to the service endpoint name and is surfaced through
  127. // serviceEndpointElement.Name
  128. // - this.Name is a token used as a key in the endpoint collection to identify
  129. // a specific bucket of configuration settings.
  130. // Thus, the Name property is skipped here.
  131. }
  132. protected internal abstract ServiceEndpoint CreateServiceEndpoint(ContractDescription contractDescription);
  133. protected abstract void OnApplyConfiguration(ServiceEndpoint endpoint, ChannelEndpointElement channelEndpointElement);
  134. protected abstract void OnApplyConfiguration(ServiceEndpoint endpoint, ServiceEndpointElement serviceEndpointElement);
  135. protected abstract void OnInitializeAndValidate(ChannelEndpointElement channelEndpointElement);
  136. protected abstract void OnInitializeAndValidate(ServiceEndpointElement serviceEndpointElement);
  137. [Fx.Tag.SecurityNote(Critical = "Accesses critical field contextHelper.")]
  138. [SecurityCritical]
  139. protected override void Reset(ConfigurationElement parentElement)
  140. {
  141. this.contextHelper.OnReset(parentElement);
  142. base.Reset(parentElement);
  143. }
  144. ContextInformation IConfigurationContextProviderInternal.GetEvaluationContext()
  145. {
  146. return this.EvaluationContext;
  147. }
  148. [Fx.Tag.SecurityNote(Critical = "Accesses critical field contextHelper.",
  149. Miscellaneous = "RequiresReview -- the return value will be used for a security decision -- see comment in interface definition.")]
  150. [SecurityCritical]
  151. ContextInformation IConfigurationContextProviderInternal.GetOriginalEvaluationContext()
  152. {
  153. return this.contextHelper.GetOriginalContext(this);
  154. }
  155. }
  156. }