2 // NetPeerTcpBindingElement.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2006-2009 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
;
37 using System
.Net
.Security
;
38 using System
.Reflection
;
39 using System
.Security
.Cryptography
.X509Certificates
;
40 using System
.Security
.Principal
;
41 using System
.IdentityModel
.Claims
;
42 using System
.IdentityModel
.Policy
;
43 using System
.IdentityModel
.Tokens
;
44 using System
.ServiceModel
;
45 using System
.ServiceModel
.Channels
;
46 using System
.ServiceModel
.Description
;
47 using System
.ServiceModel
.Diagnostics
;
48 using System
.ServiceModel
.Dispatcher
;
49 using System
.ServiceModel
.MsmqIntegration
;
50 using System
.ServiceModel
.PeerResolvers
;
51 using System
.ServiceModel
.Security
;
52 using System
.Runtime
.Serialization
;
56 namespace System
.ServiceModel
.Configuration
58 public partial class NetPeerTcpBindingElement
59 : StandardBindingElement
, IBindingConfigurationElement
61 ConfigurationPropertyCollection _properties
;
63 public NetPeerTcpBindingElement ()
67 public NetPeerTcpBindingElement (string name
) : base (name
) { }
71 protected override Type BindingElementType
{
72 get { return typeof (NetPeerTcpBinding); }
75 [MonoTODO ("get converter for IPAddress")]
76 //[TypeConverter (typeof(IPAddressConverter))]
77 [ConfigurationProperty ("listenIPAddress",
78 Options
= ConfigurationPropertyOptions
.None
,
80 public IPAddress ListenIPAddress
{
81 get { return (IPAddress) this ["listenIPAddress"]; }
82 set { this ["listenIPAddress"] = value; }
85 [ConfigurationProperty ("maxBufferPoolSize",
86 Options
= ConfigurationPropertyOptions
.None
,
87 DefaultValue
= "524288")]
88 [LongValidator ( MinValue
= 0,
89 MaxValue
= 9223372036854775807,
90 ExcludeRange
= false)]
91 public long MaxBufferPoolSize
{
92 get { return (long) this ["maxBufferPoolSize"]; }
93 set { this ["maxBufferPoolSize"] = value; }
96 [ConfigurationProperty ("maxReceivedMessageSize",
97 Options
= ConfigurationPropertyOptions
.None
,
98 DefaultValue
= "65536")]
99 [LongValidator ( MinValue
= 16384,
100 MaxValue
= 9223372036854775807,
101 ExcludeRange
= false)]
102 public long MaxReceivedMessageSize
{
103 get { return (long) this ["maxReceivedMessageSize"]; }
104 set { this ["maxReceivedMessageSize"] = value; }
107 [IntegerValidator ( MinValue
= 0,
109 ExcludeRange
= false)]
110 [ConfigurationProperty ("port",
111 Options
= ConfigurationPropertyOptions
.None
,
114 get { return (int) this ["port"]; }
115 set { this ["port"] = value; }
118 protected override ConfigurationPropertyCollection Properties
{
120 if (_properties
== null) {
121 _properties
= base.Properties
;
122 _properties
.Add (new ConfigurationProperty ("listenIPAddress", typeof (IPAddress
), null, null/* FIXME: get converter for IPAddress*/, null, ConfigurationPropertyOptions
.None
));
123 _properties
.Add (new ConfigurationProperty ("maxBufferPoolSize", typeof (long), "524288", null, null, ConfigurationPropertyOptions
.None
));
124 _properties
.Add (new ConfigurationProperty ("maxReceivedMessageSize", typeof (long), "65536", null, null, ConfigurationPropertyOptions
.None
));
125 _properties
.Add (new ConfigurationProperty ("port", typeof (int), "0", null, null, ConfigurationPropertyOptions
.None
));
126 _properties
.Add (new ConfigurationProperty ("readerQuotas", typeof (XmlDictionaryReaderQuotasElement
), null, null, null, ConfigurationPropertyOptions
.None
));
127 _properties
.Add (new ConfigurationProperty ("resolver", typeof (PeerResolverElement
), null, null, null, ConfigurationPropertyOptions
.None
));
128 _properties
.Add (new ConfigurationProperty ("security", typeof (PeerSecurityElement
), null, null, null, ConfigurationPropertyOptions
.None
));
134 [ConfigurationProperty ("readerQuotas",
135 Options
= ConfigurationPropertyOptions
.None
)]
136 public XmlDictionaryReaderQuotasElement ReaderQuotas
{
137 get { return (XmlDictionaryReaderQuotasElement) this ["readerQuotas"]; }
140 [ConfigurationProperty ("resolver",
141 Options
= ConfigurationPropertyOptions
.None
,
142 DefaultValue
= null)]
143 public PeerResolverElement Resolver
{
144 get { return (PeerResolverElement) this ["resolver"]; }
147 [ConfigurationProperty ("security",
148 Options
= ConfigurationPropertyOptions
.None
)]
149 public PeerSecurityElement Security
{
150 get { return (PeerSecurityElement) this ["security"]; }
153 protected override void OnApplyConfiguration (Binding binding
)
155 var n
= (NetPeerTcpBinding
) binding
;
156 n
.ListenIPAddress
= ListenIPAddress
;
157 n
.MaxBufferPoolSize
= MaxBufferPoolSize
;
158 n
.MaxReceivedMessageSize
= MaxReceivedMessageSize
;
160 n
.ReaderQuotas
= ReaderQuotas
.Create ();
161 if (Resolver
!= null) {
162 if (Resolver
.Custom
!= null) {
163 n
.Resolver
.Custom
.Address
= new EndpointAddress (Resolver
.Custom
.Address
, Resolver
.Custom
.Identity
.Create (), Resolver
.Custom
.Headers
.Headers
);
164 if (Resolver
.Custom
.Binding
!= null) {
165 var bcol
= ConfigUtil
.BindingsSection
[Resolver
.Custom
.Binding
];
166 var bc
= bcol
.ConfiguredBindings
.First (b
=> b
.Name
== Resolver
.Custom
.BindingConfiguration
);
167 n
.Resolver
.Custom
.Binding
= (Binding
) Activator
.CreateInstance (bcol
.BindingType
, new object[0]);
168 bc
.ApplyConfiguration (n
.Resolver
.Custom
.Binding
);
170 // FIXME: correct type instantiation.
171 if (!String
.IsNullOrEmpty (Resolver
.Custom
.ResolverType
))
172 n
.Resolver
.Custom
.Resolver
= (PeerResolver
) Activator
.CreateInstance (Type
.GetType (Resolver
.Custom
.ResolverType
), new object [0]);
174 n
.Resolver
.Mode
= Resolver
.Mode
;
175 n
.Resolver
.ReferralPolicy
= Resolver
.ReferralPolicy
;
177 if (Security
!= null) {
178 n
.Security
.Mode
= Security
.Mode
;
179 n
.Security
.Transport
.CredentialType
= Security
.Transport
.CredentialType
;