MtomMessageEncodingElement.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //------------------------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------------------------
  4. namespace System.ServiceModel.Configuration
  5. {
  6. using System.ComponentModel;
  7. using System.Configuration;
  8. using System.Globalization;
  9. using System.ServiceModel.Channels;
  10. using System.Text;
  11. public sealed partial class MtomMessageEncodingElement : BindingElementExtensionElement
  12. {
  13. public MtomMessageEncodingElement()
  14. {
  15. }
  16. public override void ApplyConfiguration(BindingElement bindingElement)
  17. {
  18. base.ApplyConfiguration(bindingElement);
  19. MtomMessageEncodingBindingElement binding = (MtomMessageEncodingBindingElement)bindingElement;
  20. binding.MessageVersion = this.MessageVersion;
  21. binding.WriteEncoding = this.WriteEncoding;
  22. binding.MaxReadPoolSize = this.MaxReadPoolSize;
  23. binding.MaxWritePoolSize = this.MaxWritePoolSize;
  24. #pragma warning suppress 56506 //[....]; base.ApplyConfiguration() checks for 'binding' being null
  25. this.ReaderQuotas.ApplyConfiguration(binding.ReaderQuotas);
  26. binding.MaxBufferSize = this.MaxBufferSize;
  27. }
  28. public override Type BindingElementType
  29. {
  30. get { return typeof(MtomMessageEncodingBindingElement); }
  31. }
  32. public override void CopyFrom(ServiceModelExtensionElement from)
  33. {
  34. base.CopyFrom(from);
  35. MtomMessageEncodingElement source = (MtomMessageEncodingElement)from;
  36. #pragma warning suppress 56506 //[....]; base.CopyFrom() checks for 'from' being null
  37. this.MessageVersion = source.MessageVersion;
  38. this.WriteEncoding = source.WriteEncoding;
  39. this.MaxReadPoolSize = source.MaxReadPoolSize;
  40. this.MaxWritePoolSize = source.MaxWritePoolSize;
  41. this.MaxBufferSize = source.MaxBufferSize;
  42. }
  43. protected internal override BindingElement CreateBindingElement()
  44. {
  45. MtomMessageEncodingBindingElement binding = new MtomMessageEncodingBindingElement();
  46. this.ApplyConfiguration(binding);
  47. return binding;
  48. }
  49. protected internal override void InitializeFrom(BindingElement bindingElement)
  50. {
  51. base.InitializeFrom(bindingElement);
  52. MtomMessageEncodingBindingElement binding = (MtomMessageEncodingBindingElement)bindingElement;
  53. SetPropertyValueIfNotDefaultValue(ConfigurationStrings.MessageVersion, binding.MessageVersion);
  54. SetPropertyValueIfNotDefaultValue(ConfigurationStrings.WriteEncoding, binding.WriteEncoding);
  55. SetPropertyValueIfNotDefaultValue(ConfigurationStrings.MaxReadPoolSize, binding.MaxReadPoolSize);
  56. SetPropertyValueIfNotDefaultValue(ConfigurationStrings.MaxWritePoolSize, binding.MaxWritePoolSize);
  57. this.ReaderQuotas.InitializeFrom(binding.ReaderQuotas);
  58. SetPropertyValueIfNotDefaultValue(ConfigurationStrings.MaxBufferSize, binding.MaxBufferSize);
  59. }
  60. [ConfigurationProperty(ConfigurationStrings.MaxReadPoolSize, DefaultValue = EncoderDefaults.MaxReadPoolSize)]
  61. [IntegerValidator(MinValue = 1)]
  62. public int MaxReadPoolSize
  63. {
  64. get { return (int)base[ConfigurationStrings.MaxReadPoolSize]; }
  65. set { base[ConfigurationStrings.MaxReadPoolSize] = value; }
  66. }
  67. [ConfigurationProperty(ConfigurationStrings.MaxWritePoolSize, DefaultValue = EncoderDefaults.MaxWritePoolSize)]
  68. [IntegerValidator(MinValue = 1)]
  69. public int MaxWritePoolSize
  70. {
  71. get { return (int)base[ConfigurationStrings.MaxWritePoolSize]; }
  72. set { base[ConfigurationStrings.MaxWritePoolSize] = value; }
  73. }
  74. [ConfigurationProperty(ConfigurationStrings.MessageVersion, DefaultValue = TextEncoderDefaults.MessageVersionString)]
  75. [TypeConverter(typeof(MessageVersionConverter))]
  76. public MessageVersion MessageVersion
  77. {
  78. get { return (MessageVersion)base[ConfigurationStrings.MessageVersion]; }
  79. set { base[ConfigurationStrings.MessageVersion] = value; }
  80. }
  81. [ConfigurationProperty(ConfigurationStrings.ReaderQuotas)]
  82. public XmlDictionaryReaderQuotasElement ReaderQuotas
  83. {
  84. get { return (XmlDictionaryReaderQuotasElement) base[ConfigurationStrings.ReaderQuotas]; }
  85. }
  86. [ConfigurationProperty(ConfigurationStrings.MaxBufferSize, DefaultValue = MtomEncoderDefaults.MaxBufferSize)]
  87. [IntegerValidator(MinValue = 1)]
  88. public int MaxBufferSize
  89. {
  90. get { return (int)base[ConfigurationStrings.MaxBufferSize]; }
  91. set { base[ConfigurationStrings.MaxBufferSize] = value; }
  92. }
  93. [ConfigurationProperty(ConfigurationStrings.WriteEncoding, DefaultValue = TextEncoderDefaults.EncodingString)]
  94. [TypeConverter(typeof(EncodingConverter))]
  95. public Encoding WriteEncoding
  96. {
  97. get { return (Encoding)base[ConfigurationStrings.WriteEncoding]; }
  98. set { base[ConfigurationStrings.WriteEncoding] = value; }
  99. }
  100. }
  101. }