2 // HttpBindingBaseElement.cs
4 // This is a .NET 4.5 addition and contains most of the code from
5 // BasicHttpBindingElement.
9 // Atsushi Enomoto <atsushi@ximian.com>
10 // Martin Baulig <martin.baulig@xamarin.com>
12 // Copyright (C) 2006 Novell, Inc. http://www.novell.com
13 // Copyright (c) 2012 Xamarin Inc. (http://www.xamarin.com)
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 using System.Collections;
37 using System.Collections.Generic;
38 using System.Collections.ObjectModel;
39 using System.ComponentModel;
40 using System.Configuration;
42 using System.Net.Security;
43 using System.Reflection;
44 using System.Security.Cryptography.X509Certificates;
45 using System.Security.Principal;
46 using System.IdentityModel.Claims;
47 using System.IdentityModel.Policy;
48 using System.IdentityModel.Tokens;
49 using System.ServiceModel;
50 using System.ServiceModel.Channels;
51 using System.ServiceModel.Description;
52 using System.ServiceModel.Diagnostics;
53 using System.ServiceModel.Dispatcher;
54 using System.ServiceModel.MsmqIntegration;
55 using System.ServiceModel.PeerResolvers;
56 using System.ServiceModel.Security;
57 using System.Runtime.Serialization;
61 namespace System.ServiceModel.Configuration
63 public abstract class HttpBindingBaseElement
64 : StandardBindingElement, IBindingConfigurationElement
66 ConfigurationPropertyCollection _properties;
68 public HttpBindingBaseElement ()
72 public HttpBindingBaseElement (string name) : base (name) { }
76 [ConfigurationProperty ("allowCookies",
78 Options = ConfigurationPropertyOptions.None)]
79 public bool AllowCookies {
80 get { return (bool) this ["allowCookies"]; }
81 set { this ["allowCookies"] = value; }
84 [ConfigurationProperty ("bypassProxyOnLocal",
86 Options = ConfigurationPropertyOptions.None)]
87 public bool BypassProxyOnLocal {
88 get { return (bool) this ["bypassProxyOnLocal"]; }
89 set { this ["bypassProxyOnLocal"] = value; }
92 [ConfigurationProperty ("hostNameComparisonMode",
93 DefaultValue = "StrongWildcard",
94 Options = ConfigurationPropertyOptions.None)]
95 public HostNameComparisonMode HostNameComparisonMode {
96 get { return (HostNameComparisonMode) this ["hostNameComparisonMode"]; }
97 set { this ["hostNameComparisonMode"] = value; }
100 [LongValidator ( MinValue = 0,
101 MaxValue = 9223372036854775807,
102 ExcludeRange = false)]
103 [ConfigurationProperty ("maxBufferPoolSize",
104 DefaultValue = "524288",
105 Options = ConfigurationPropertyOptions.None)]
106 public long MaxBufferPoolSize {
107 get { return (long) this ["maxBufferPoolSize"]; }
108 set { this ["maxBufferPoolSize"] = value; }
111 [IntegerValidator ( MinValue = 1,
112 MaxValue = int.MaxValue,
113 ExcludeRange = false)]
114 [ConfigurationProperty ("maxBufferSize",
115 DefaultValue = "65536",
116 Options = ConfigurationPropertyOptions.None)]
117 public int MaxBufferSize {
118 get { return (int) this ["maxBufferSize"]; }
119 set { this ["maxBufferSize"] = value; }
122 [LongValidator ( MinValue = 1,
123 MaxValue = 9223372036854775807,
124 ExcludeRange = false)]
125 [ConfigurationProperty ("maxReceivedMessageSize",
126 DefaultValue = "65536",
127 Options = ConfigurationPropertyOptions.None)]
128 public long MaxReceivedMessageSize {
129 get { return (long) this ["maxReceivedMessageSize"]; }
130 set { this ["maxReceivedMessageSize"] = value; }
133 protected override ConfigurationPropertyCollection Properties {
135 if (_properties == null) {
136 _properties = base.Properties;
137 _properties.Add (new ConfigurationProperty ("allowCookies", typeof (bool), "false", null, null, ConfigurationPropertyOptions.None));
138 _properties.Add (new ConfigurationProperty ("bypassProxyOnLocal", typeof (bool), "false", null, null, ConfigurationPropertyOptions.None));
139 _properties.Add (new ConfigurationProperty ("hostNameComparisonMode", typeof (HostNameComparisonMode), "StrongWildcard", null, null, ConfigurationPropertyOptions.None));
140 _properties.Add (new ConfigurationProperty ("maxBufferPoolSize", typeof (long), "524288", null, new LongValidator (0, 9223372036854775807, false), ConfigurationPropertyOptions.None));
141 _properties.Add (new ConfigurationProperty ("maxBufferSize", typeof (int), "65536", null, new IntegerValidator (1, int.MaxValue, false), ConfigurationPropertyOptions.None));
142 _properties.Add (new ConfigurationProperty ("maxReceivedMessageSize", typeof (long), "65536", null, new LongValidator (1, 9223372036854775807, false), ConfigurationPropertyOptions.None));
143 _properties.Add (new ConfigurationProperty ("proxyAddress", typeof (Uri), null, new UriTypeConverter (), null, ConfigurationPropertyOptions.None));
144 _properties.Add (new ConfigurationProperty ("readerQuotas", typeof (XmlDictionaryReaderQuotasElement), null, null, null, ConfigurationPropertyOptions.None));
145 _properties.Add (new ConfigurationProperty ("textEncoding", typeof (Encoding), HttpBindingBase.DefaultTextEncoding, EncodingConverter.Instance, null, ConfigurationPropertyOptions.None));
146 _properties.Add (new ConfigurationProperty ("transferMode", typeof (TransferMode), "Buffered", null, null, ConfigurationPropertyOptions.None));
147 _properties.Add (new ConfigurationProperty ("useDefaultWebProxy", typeof (bool), "true", new BooleanConverter (), null, ConfigurationPropertyOptions.None));
153 [ConfigurationProperty ("proxyAddress",
155 Options = ConfigurationPropertyOptions.None)]
156 public Uri ProxyAddress {
157 get { return (Uri) this ["proxyAddress"]; }
158 set { this ["proxyAddress"] = value; }
161 [ConfigurationProperty ("readerQuotas",
162 Options = ConfigurationPropertyOptions.None)]
163 public XmlDictionaryReaderQuotasElement ReaderQuotas {
164 get { return (XmlDictionaryReaderQuotasElement) this ["readerQuotas"]; }
167 [TypeConverter (typeof (EncodingConverter))]
168 [ConfigurationProperty ("textEncoding",
169 DefaultValue = "utf-8",
170 Options = ConfigurationPropertyOptions.None)]
171 public Encoding TextEncoding {
172 get { return (Encoding) this ["textEncoding"]; }
173 set { this ["textEncoding"] = value; }
176 [ConfigurationProperty ("transferMode",
177 DefaultValue = "Buffered",
178 Options = ConfigurationPropertyOptions.None)]
179 public TransferMode TransferMode {
180 get { return (TransferMode) this ["transferMode"]; }
181 set { this ["transferMode"] = value; }
184 [ConfigurationProperty ("useDefaultWebProxy",
186 Options = ConfigurationPropertyOptions.None)]
187 public bool UseDefaultWebProxy {
188 get { return (bool) this ["useDefaultWebProxy"]; }
189 set { this ["useDefaultWebProxy"] = value; }
192 protected override void OnApplyConfiguration (Binding binding)
194 HttpBindingBase basicHttpBinding = (HttpBindingBase) binding;
196 basicHttpBinding.AllowCookies = AllowCookies;
197 basicHttpBinding.BypassProxyOnLocal = BypassProxyOnLocal;
198 basicHttpBinding.HostNameComparisonMode = HostNameComparisonMode;
199 basicHttpBinding.MaxBufferPoolSize = MaxBufferPoolSize;
200 basicHttpBinding.MaxBufferSize = MaxBufferSize;
201 basicHttpBinding.MaxReceivedMessageSize = MaxReceivedMessageSize;
202 basicHttpBinding.ProxyAddress = ProxyAddress;
204 ReaderQuotas.ApplyConfiguration (basicHttpBinding.ReaderQuotas);
206 basicHttpBinding.TextEncoding = TextEncoding;
207 basicHttpBinding.TransferMode = TransferMode;
208 basicHttpBinding.UseDefaultWebProxy = UseDefaultWebProxy;
211 protected internal override void InitializeFrom (Binding binding)
213 HttpBindingBase b = (HttpBindingBase) binding;
215 base.InitializeFrom (binding);
216 AllowCookies = b.AllowCookies;
217 BypassProxyOnLocal = b.BypassProxyOnLocal;
218 HostNameComparisonMode = b.HostNameComparisonMode;
219 MaxBufferPoolSize = b.MaxBufferPoolSize;
220 MaxBufferSize = b.MaxBufferSize;
221 MaxReceivedMessageSize = b.MaxReceivedMessageSize;
222 ProxyAddress = b.ProxyAddress;
224 ReaderQuotas.ApplyConfiguration (b.ReaderQuotas);
226 TextEncoding = b.TextEncoding;
227 TransferMode = b.TransferMode;
228 UseDefaultWebProxy = b.UseDefaultWebProxy;