NetPeerTcpBindingElement.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //------------------------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------------------------
  4. namespace System.ServiceModel.Configuration
  5. {
  6. using System.Net;
  7. using System.Collections.Generic;
  8. using System.ServiceModel;
  9. using System.Configuration;
  10. using System.Globalization;
  11. using System.ServiceModel.Channels;
  12. [ObsoleteAttribute ("PeerChannel feature is obsolete and will be removed in the future.", false)]
  13. public partial class NetPeerTcpBindingElement : StandardBindingElement
  14. {
  15. public NetPeerTcpBindingElement(string name)
  16. : base(name)
  17. {
  18. }
  19. public NetPeerTcpBindingElement()
  20. : this(null)
  21. {
  22. }
  23. protected override Type BindingElementType
  24. {
  25. get { return typeof(NetPeerTcpBinding); }
  26. }
  27. [ConfigurationProperty(ConfigurationStrings.ListenIPAddress, DefaultValue = PeerTransportDefaults.ListenIPAddress)]
  28. [System.ComponentModel.TypeConverter(typeof(PeerTransportListenAddressConverter))]
  29. [PeerTransportListenAddressValidator()]
  30. public IPAddress ListenIPAddress
  31. {
  32. get { return (IPAddress)base[ConfigurationStrings.ListenIPAddress]; }
  33. set { base[ConfigurationStrings.ListenIPAddress] = value; }
  34. }
  35. [ConfigurationProperty(ConfigurationStrings.MaxBufferPoolSize, DefaultValue = TransportDefaults.MaxBufferPoolSize)]
  36. [LongValidator(MinValue = 0)]
  37. public long MaxBufferPoolSize
  38. {
  39. get { return (long)base[ConfigurationStrings.MaxBufferPoolSize]; }
  40. set { base[ConfigurationStrings.MaxBufferPoolSize] = value; }
  41. }
  42. [ConfigurationProperty(ConfigurationStrings.MaxReceivedMessageSize, DefaultValue = TransportDefaults.MaxReceivedMessageSize)]
  43. [LongValidator(MinValue = PeerTransportConstants.MinMessageSize)]
  44. public long MaxReceivedMessageSize
  45. {
  46. get { return (long)base[ConfigurationStrings.MaxReceivedMessageSize]; }
  47. set { base[ConfigurationStrings.MaxReceivedMessageSize] = value; }
  48. }
  49. [ConfigurationProperty(ConfigurationStrings.Port, DefaultValue = PeerTransportDefaults.Port)]
  50. [IntegerValidator(MinValue = PeerTransportConstants.MinPort, MaxValue = PeerTransportConstants.MaxPort)]
  51. public int Port
  52. {
  53. get { return (int)base[ConfigurationStrings.Port]; }
  54. set { base[ConfigurationStrings.Port] = value; }
  55. }
  56. [ConfigurationProperty(ConfigurationStrings.ReaderQuotas)]
  57. public XmlDictionaryReaderQuotasElement ReaderQuotas
  58. {
  59. get { return (XmlDictionaryReaderQuotasElement)base[ConfigurationStrings.ReaderQuotas]; }
  60. }
  61. [ConfigurationProperty(ConfigurationStrings.PeerResolver, DefaultValue = null)]
  62. public PeerResolverElement Resolver
  63. {
  64. get { return (PeerResolverElement)base[ConfigurationStrings.PeerResolver]; }
  65. }
  66. [ConfigurationProperty(ConfigurationStrings.Security)]
  67. public PeerSecurityElement Security
  68. {
  69. get { return (PeerSecurityElement)base[ConfigurationStrings.Security]; }
  70. }
  71. protected internal override void InitializeFrom(Binding binding)
  72. {
  73. base.InitializeFrom(binding);
  74. NetPeerTcpBinding peerBinding = (NetPeerTcpBinding)binding;
  75. SetPropertyValueIfNotDefaultValue(ConfigurationStrings.ListenIPAddress, peerBinding.ListenIPAddress);
  76. SetPropertyValueIfNotDefaultValue(ConfigurationStrings.MaxBufferPoolSize, peerBinding.MaxBufferPoolSize);
  77. SetPropertyValueIfNotDefaultValue(ConfigurationStrings.MaxReceivedMessageSize, peerBinding.MaxReceivedMessageSize);
  78. SetPropertyValueIfNotDefaultValue(ConfigurationStrings.Port, peerBinding.Port);
  79. this.Security.InitializeFrom(peerBinding.Security);
  80. this.Resolver.InitializeFrom(peerBinding.Resolver);
  81. this.ReaderQuotas.InitializeFrom(peerBinding.ReaderQuotas);
  82. }
  83. protected override void OnApplyConfiguration(Binding binding)
  84. {
  85. NetPeerTcpBinding peerBinding = (NetPeerTcpBinding)binding;
  86. peerBinding.ListenIPAddress = this.ListenIPAddress;
  87. peerBinding.MaxBufferPoolSize = this.MaxBufferPoolSize;
  88. peerBinding.MaxReceivedMessageSize = this.MaxReceivedMessageSize;
  89. peerBinding.Port = this.Port;
  90. peerBinding.Security = new PeerSecuritySettings();
  91. this.ReaderQuotas.ApplyConfiguration(peerBinding.ReaderQuotas);
  92. this.Resolver.ApplyConfiguration(peerBinding.Resolver);
  93. this.Security.ApplyConfiguration(peerBinding.Security);
  94. }
  95. }
  96. }