EndpointAddressElementBase.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //------------------------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------------------------
  4. namespace System.ServiceModel.Configuration
  5. {
  6. using System;
  7. using System.ServiceModel;
  8. using System.Configuration;
  9. using System.ServiceModel.Channels;
  10. using System.Xml;
  11. public partial class EndpointAddressElementBase : ServiceModelConfigurationElement
  12. {
  13. protected EndpointAddressElementBase()
  14. {
  15. }
  16. [ConfigurationProperty(ConfigurationStrings.Address, DefaultValue = null, Options = ConfigurationPropertyOptions.IsRequired)]
  17. public Uri Address
  18. {
  19. get { return (Uri)base[ConfigurationStrings.Address]; }
  20. set { base[ConfigurationStrings.Address] = value; }
  21. }
  22. [ConfigurationProperty(ConfigurationStrings.Headers)]
  23. public AddressHeaderCollectionElement Headers
  24. {
  25. get { return (AddressHeaderCollectionElement)base[ConfigurationStrings.Headers]; }
  26. }
  27. [ConfigurationProperty(ConfigurationStrings.Identity)]
  28. public IdentityElement Identity
  29. {
  30. get { return (IdentityElement)base[ConfigurationStrings.Identity]; }
  31. }
  32. internal protected void Copy(EndpointAddressElementBase source)
  33. {
  34. if (this.IsReadOnly())
  35. {
  36. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.GetString(SR.ConfigReadOnly)));
  37. }
  38. if (null == source)
  39. {
  40. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("source");
  41. }
  42. this.Address = source.Address;
  43. this.Headers.Headers = source.Headers.Headers;
  44. PropertyInformationCollection properties = source.ElementInformation.Properties;
  45. if (properties[ConfigurationStrings.Identity].ValueOrigin != PropertyValueOrigin.Default)
  46. {
  47. this.Identity.Copy(source.Identity);
  48. }
  49. }
  50. public void InitializeFrom(EndpointAddress endpointAddress)
  51. {
  52. if (null == endpointAddress)
  53. {
  54. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("endpointAddress");
  55. }
  56. SetPropertyValueIfNotDefaultValue(ConfigurationStrings.Address, endpointAddress.Uri);
  57. this.Headers.InitializeFrom(endpointAddress.Headers);
  58. if (null != endpointAddress.Identity)
  59. {
  60. this.Identity.InitializeFrom(endpointAddress.Identity);
  61. }
  62. }
  63. }
  64. }