2 // NetTcpBindingElement.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2006 Novell, Inc. http://www.novell.com
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using System
.Collections
;
31 using System
.Collections
.Generic
;
32 using System
.Collections
.ObjectModel
;
33 using System
.ComponentModel
;
34 using System
.Configuration
;
36 using System
.Net
.Security
;
37 using System
.Reflection
;
38 using System
.Security
.Cryptography
.X509Certificates
;
39 using System
.Security
.Principal
;
40 using System
.IdentityModel
.Claims
;
41 using System
.IdentityModel
.Policy
;
42 using System
.IdentityModel
.Tokens
;
43 using System
.ServiceModel
;
44 using System
.ServiceModel
.Channels
;
45 using System
.ServiceModel
.Description
;
46 using System
.ServiceModel
.Diagnostics
;
47 using System
.ServiceModel
.Dispatcher
;
48 using System
.ServiceModel
.MsmqIntegration
;
49 using System
.ServiceModel
.PeerResolvers
;
50 using System
.ServiceModel
.Security
;
51 using System
.Runtime
.Serialization
;
55 namespace System
.ServiceModel
.Configuration
57 public partial class NetTcpBindingElement
58 : StandardBindingElement
, IBindingConfigurationElement
60 ConfigurationPropertyCollection _properties
;
62 public NetTcpBindingElement ()
65 public NetTcpBindingElement (string name
) : base (name
) { }
70 protected override Type BindingElementType
{
71 get { return typeof (NetTcpBinding); }
74 [ConfigurationProperty ("hostNameComparisonMode",
75 Options
= ConfigurationPropertyOptions
.None
,
76 DefaultValue
= "StrongWildcard")]
77 public HostNameComparisonMode HostNameComparisonMode
{
78 get { return (HostNameComparisonMode) this ["hostNameComparisonMode"]; }
79 set { this ["hostNameComparisonMode"] = value; }
82 [ConfigurationProperty ("listenBacklog",
83 Options
= ConfigurationPropertyOptions
.None
,
85 [IntegerValidator ( MinValue
= 1,
86 MaxValue
= int.MaxValue
,
87 ExcludeRange
= false)]
88 public int ListenBacklog
{
89 get { return (int) this ["listenBacklog"]; }
90 set { this ["listenBacklog"] = value; }
93 [LongValidator ( MinValue
= 0,
94 MaxValue
= 9223372036854775807,
95 ExcludeRange
= false)]
96 [ConfigurationProperty ("maxBufferPoolSize",
97 Options
= ConfigurationPropertyOptions
.None
,
98 DefaultValue
= "524288")]
99 public long MaxBufferPoolSize
{
100 get { return (long) this ["maxBufferPoolSize"]; }
101 set { this ["maxBufferPoolSize"] = value; }
104 [ConfigurationProperty ("maxBufferSize",
105 Options
= ConfigurationPropertyOptions
.None
,
106 DefaultValue
= "65536")]
107 [IntegerValidator ( MinValue
= 1,
108 MaxValue
= int.MaxValue
,
109 ExcludeRange
= false)]
110 public int MaxBufferSize
{
111 get { return (int) this ["maxBufferSize"]; }
112 set { this ["maxBufferSize"] = value; }
115 [IntegerValidator ( MinValue
= 1,
116 MaxValue
= int.MaxValue
,
117 ExcludeRange
= false)]
118 [ConfigurationProperty ("maxConnections",
119 Options
= ConfigurationPropertyOptions
.None
,
120 DefaultValue
= "10")]
121 public int MaxConnections
{
122 get { return (int) this ["maxConnections"]; }
123 set { this ["maxConnections"] = value; }
126 [LongValidator ( MinValue
= 1,
127 MaxValue
= 9223372036854775807,
128 ExcludeRange
= false)]
129 [ConfigurationProperty ("maxReceivedMessageSize",
130 Options
= ConfigurationPropertyOptions
.None
,
131 DefaultValue
= "65536")]
132 public long MaxReceivedMessageSize
{
133 get { return (long) this ["maxReceivedMessageSize"]; }
134 set { this ["maxReceivedMessageSize"] = value; }
137 [ConfigurationProperty ("portSharingEnabled",
138 Options
= ConfigurationPropertyOptions
.None
,
139 DefaultValue
= false)]
140 public bool PortSharingEnabled
{
141 get { return (bool) this ["portSharingEnabled"]; }
142 set { this ["portSharingEnabled"] = value; }
145 protected override ConfigurationPropertyCollection Properties
{
147 if (_properties
== null) {
148 _properties
= base.Properties
;
149 _properties
.Add (new ConfigurationProperty ("hostNameComparisonMode", typeof (HostNameComparisonMode
), "StrongWildcard", null, null, ConfigurationPropertyOptions
.None
));
150 _properties
.Add (new ConfigurationProperty ("listenBacklog", typeof (int), "10", null, new IntegerValidator (1, int.MaxValue
, false), ConfigurationPropertyOptions
.None
));
151 _properties
.Add (new ConfigurationProperty ("maxBufferPoolSize", typeof (long), "524288", null, new LongValidator (0, 9223372036854775807, false), ConfigurationPropertyOptions
.None
));
152 _properties
.Add (new ConfigurationProperty ("maxBufferSize", typeof (int), "65536", null, new IntegerValidator (1, int.MaxValue
, false), ConfigurationPropertyOptions
.None
));
153 _properties
.Add (new ConfigurationProperty ("maxConnections", typeof (int), "10", null, new IntegerValidator (1, int.MaxValue
, false), ConfigurationPropertyOptions
.None
));
154 _properties
.Add (new ConfigurationProperty ("maxReceivedMessageSize", typeof (long), "65536", null, new LongValidator (1, 9223372036854775807, false), ConfigurationPropertyOptions
.None
));
155 _properties
.Add (new ConfigurationProperty ("portSharingEnabled", typeof (bool), "false", null, null, ConfigurationPropertyOptions
.None
));
156 _properties
.Add (new ConfigurationProperty ("readerQuotas", typeof (XmlDictionaryReaderQuotasElement
), null, null, null, ConfigurationPropertyOptions
.None
));
157 _properties
.Add (new ConfigurationProperty ("reliableSession", typeof (StandardBindingOptionalReliableSessionElement
), null, null, null, ConfigurationPropertyOptions
.None
));
158 _properties
.Add (new ConfigurationProperty ("security", typeof (NetTcpSecurityElement
), null, null, null, ConfigurationPropertyOptions
.None
));
159 _properties
.Add (new ConfigurationProperty ("transactionFlow", typeof (bool), "false", null, null, ConfigurationPropertyOptions
.None
));
160 _properties
.Add (new ConfigurationProperty ("transactionProtocol", typeof (TransactionProtocol
), "OleTransactions", TransactionProtocolConverter
.Instance
, null, ConfigurationPropertyOptions
.None
));
161 _properties
.Add (new ConfigurationProperty ("transferMode", typeof (TransferMode
), "Buffered", null, null, ConfigurationPropertyOptions
.None
));
167 [ConfigurationProperty ("readerQuotas",
168 Options
= ConfigurationPropertyOptions
.None
)]
169 public XmlDictionaryReaderQuotasElement ReaderQuotas
{
170 get { return (XmlDictionaryReaderQuotasElement) this ["readerQuotas"]; }
173 [MonoTODO ("This configuration prpperty is not applied yet")]
174 [ConfigurationProperty ("reliableSession",
175 Options
= ConfigurationPropertyOptions
.None
)]
176 public StandardBindingOptionalReliableSessionElement ReliableSession
{
177 get { return (StandardBindingOptionalReliableSessionElement) this ["reliableSession"]; }
180 [ConfigurationProperty ("security",
181 Options
= ConfigurationPropertyOptions
.None
)]
182 public NetTcpSecurityElement Security
{
183 get { return (NetTcpSecurityElement) this ["security"]; }
186 [ConfigurationProperty ("transactionFlow",
187 Options
= ConfigurationPropertyOptions
.None
,
188 DefaultValue
= false)]
189 public bool TransactionFlow
{
190 get { return (bool) this ["transactionFlow"]; }
191 set { this ["transactionFlow"] = value; }
194 [TypeConverter (typeof (TransactionProtocolConverter
))]
195 [ConfigurationProperty ("transactionProtocol",
196 Options
= ConfigurationPropertyOptions
.None
,
197 DefaultValue
= "OleTransactions")]
198 public TransactionProtocol TransactionProtocol
{
199 get { return (TransactionProtocol) this ["transactionProtocol"]; }
200 set { this ["transactionProtocol"] = value; }
203 [ConfigurationProperty ("transferMode",
204 Options
= ConfigurationPropertyOptions
.None
,
205 DefaultValue
= "Buffered")]
206 public TransferMode TransferMode
{
207 get { return (TransferMode) this ["transferMode"]; }
208 set { this ["transferMode"] = value; }
211 protected override void OnApplyConfiguration (Binding binding
)
213 NetTcpBinding n
= (NetTcpBinding
) binding
;
214 n
.CloseTimeout
= CloseTimeout
;
215 n
.HostNameComparisonMode
= HostNameComparisonMode
;
216 n
.ListenBacklog
= ListenBacklog
;
217 n
.MaxBufferPoolSize
= MaxBufferPoolSize
;
218 n
.MaxBufferSize
= MaxBufferSize
;
219 n
.MaxConnections
= MaxConnections
;
220 n
.MaxReceivedMessageSize
= MaxReceivedMessageSize
;
221 n
.OpenTimeout
= OpenTimeout
;
222 n
.PortSharingEnabled
= PortSharingEnabled
;
223 if (ReaderQuotas
!= null)
224 n
.ReaderQuotas
= ReaderQuotas
.Create ();
225 n
.ReceiveTimeout
= ReceiveTimeout
;
227 // FIXME: apply this too.
228 //ReliableSession.ApplyTo (n.ReliableSession);
230 if (Security
!= null) {
231 n
.Security
.Mode
= Security
.Mode
;
232 if (Security
.Message
!= null) {
233 n
.Security
.Message
.AlgorithmSuite
= Security
.Message
.AlgorithmSuite
;
234 n
.Security
.Message
.ClientCredentialType
= Security
.Message
.ClientCredentialType
;
236 if (Security
.Transport
!= null) {
237 n
.Security
.Transport
.ClientCredentialType
= Security
.Transport
.ClientCredentialType
;
238 n
.Security
.Transport
.ProtectionLevel
= Security
.Transport
.ProtectionLevel
;
242 n
.SendTimeout
= SendTimeout
;
243 n
.TransactionFlow
= TransactionFlow
;
244 n
.TransactionProtocol
= TransactionProtocol
;
245 n
.TransferMode
= TransferMode
;