2 // BasicHttpBindingElement.cs
4 // See BasicHttpBindingElement_4_5.cs and HttpBindingBaseElement.cs
5 // for the .NET 4.5 version of this class, where most of the code has
6 // been moved into the new abstract HttpBindingBaseElement class.
10 // Atsushi Enomoto <atsushi@ximian.com>
12 // Copyright (C) 2006 Novell, Inc. http://www.novell.com
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // 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 class BasicHttpBindingElement
64 : StandardBindingElement, IBindingConfigurationElement
66 ConfigurationPropertyCollection _properties;
68 public BasicHttpBindingElement ()
72 public BasicHttpBindingElement (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 protected override Type BindingElementType {
85 get { return typeof (BasicHttpBinding); }
88 [ConfigurationProperty ("bypassProxyOnLocal",
90 Options = ConfigurationPropertyOptions.None)]
91 public bool BypassProxyOnLocal {
92 get { return (bool) this ["bypassProxyOnLocal"]; }
93 set { this ["bypassProxyOnLocal"] = value; }
96 [ConfigurationProperty ("hostNameComparisonMode",
97 DefaultValue = "StrongWildcard",
98 Options = ConfigurationPropertyOptions.None)]
99 public HostNameComparisonMode HostNameComparisonMode {
100 get { return (HostNameComparisonMode) this ["hostNameComparisonMode"]; }
101 set { this ["hostNameComparisonMode"] = value; }
104 [LongValidator ( MinValue = 0,
105 MaxValue = 9223372036854775807,
106 ExcludeRange = false)]
107 [ConfigurationProperty ("maxBufferPoolSize",
108 DefaultValue = "524288",
109 Options = ConfigurationPropertyOptions.None)]
110 public long MaxBufferPoolSize {
111 get { return (long) this ["maxBufferPoolSize"]; }
112 set { this ["maxBufferPoolSize"] = value; }
115 [IntegerValidator ( MinValue = 1,
116 MaxValue = int.MaxValue,
117 ExcludeRange = false)]
118 [ConfigurationProperty ("maxBufferSize",
119 DefaultValue = "65536",
120 Options = ConfigurationPropertyOptions.None)]
121 public int MaxBufferSize {
122 get { return (int) this ["maxBufferSize"]; }
123 set { this ["maxBufferSize"] = value; }
126 [LongValidator ( MinValue = 1,
127 MaxValue = 9223372036854775807,
128 ExcludeRange = false)]
129 [ConfigurationProperty ("maxReceivedMessageSize",
130 DefaultValue = "65536",
131 Options = ConfigurationPropertyOptions.None)]
132 public long MaxReceivedMessageSize {
133 get { return (long) this ["maxReceivedMessageSize"]; }
134 set { this ["maxReceivedMessageSize"] = value; }
137 [ConfigurationProperty ("messageEncoding",
138 DefaultValue = "Text",
139 Options = ConfigurationPropertyOptions.None)]
140 public WSMessageEncoding MessageEncoding {
141 get { return (WSMessageEncoding) this ["messageEncoding"]; }
142 set { this ["messageEncoding"] = value; }
145 protected override ConfigurationPropertyCollection Properties {
147 if (_properties == null) {
148 _properties = base.Properties;
149 _properties.Add (new ConfigurationProperty ("allowCookies", typeof (bool), "false", null, null, ConfigurationPropertyOptions.None));
150 _properties.Add (new ConfigurationProperty ("bypassProxyOnLocal", typeof (bool), "false", null, null, ConfigurationPropertyOptions.None));
151 _properties.Add (new ConfigurationProperty ("hostNameComparisonMode", typeof (HostNameComparisonMode), "StrongWildcard", null, null, ConfigurationPropertyOptions.None));
152 _properties.Add (new ConfigurationProperty ("maxBufferPoolSize", typeof (long), "524288", null, new LongValidator (0, 9223372036854775807, false), ConfigurationPropertyOptions.None));
153 _properties.Add (new ConfigurationProperty ("maxBufferSize", typeof (int), "65536", 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 ("messageEncoding", typeof (WSMessageEncoding), "Text", null, null, ConfigurationPropertyOptions.None));
156 _properties.Add (new ConfigurationProperty ("proxyAddress", typeof (Uri), null, new UriTypeConverter (), null, ConfigurationPropertyOptions.None));
157 _properties.Add (new ConfigurationProperty ("readerQuotas", typeof (XmlDictionaryReaderQuotasElement), null, null, null, ConfigurationPropertyOptions.None));
158 _properties.Add (new ConfigurationProperty ("security", typeof (BasicHttpSecurityElement), null, null, null, ConfigurationPropertyOptions.None));
159 _properties.Add (new ConfigurationProperty ("textEncoding", typeof (Encoding), "utf-8", EncodingConverter.Instance, null, ConfigurationPropertyOptions.None));
160 _properties.Add (new ConfigurationProperty ("transferMode", typeof (TransferMode), "Buffered", null, null, ConfigurationPropertyOptions.None));
161 _properties.Add (new ConfigurationProperty ("useDefaultWebProxy", typeof (bool), "true", new BooleanConverter (), null, ConfigurationPropertyOptions.None));
167 [ConfigurationProperty ("proxyAddress",
169 Options = ConfigurationPropertyOptions.None)]
170 public Uri ProxyAddress {
171 get { return (Uri) this ["proxyAddress"]; }
172 set { this ["proxyAddress"] = value; }
175 [ConfigurationProperty ("readerQuotas",
176 Options = ConfigurationPropertyOptions.None)]
177 public XmlDictionaryReaderQuotasElement ReaderQuotas {
178 get { return (XmlDictionaryReaderQuotasElement) this ["readerQuotas"]; }
181 [ConfigurationProperty ("security",
182 Options = ConfigurationPropertyOptions.None)]
183 public BasicHttpSecurityElement Security {
184 get { return (BasicHttpSecurityElement) this ["security"]; }
187 [TypeConverter (typeof (EncodingConverter))]
188 [ConfigurationProperty ("textEncoding",
189 DefaultValue = "utf-8",
190 Options = ConfigurationPropertyOptions.None)]
191 public Encoding TextEncoding {
192 get { return (Encoding) this ["textEncoding"]; }
193 set { this ["textEncoding"] = value; }
196 [ConfigurationProperty ("transferMode",
197 DefaultValue = "Buffered",
198 Options = ConfigurationPropertyOptions.None)]
199 public TransferMode TransferMode {
200 get { return (TransferMode) this ["transferMode"]; }
201 set { this ["transferMode"] = value; }
204 [ConfigurationProperty ("useDefaultWebProxy",
206 Options = ConfigurationPropertyOptions.None)]
207 public bool UseDefaultWebProxy {
208 get { return (bool) this ["useDefaultWebProxy"]; }
209 set { this ["useDefaultWebProxy"] = value; }
212 protected override void OnApplyConfiguration (Binding binding)
214 BasicHttpBinding basicHttpBinding = (BasicHttpBinding) binding;
216 basicHttpBinding.AllowCookies = AllowCookies;
217 basicHttpBinding.BypassProxyOnLocal = BypassProxyOnLocal;
218 basicHttpBinding.HostNameComparisonMode = HostNameComparisonMode;
219 basicHttpBinding.MaxBufferPoolSize = MaxBufferPoolSize;
220 basicHttpBinding.MaxBufferSize = MaxBufferSize;
221 basicHttpBinding.MaxReceivedMessageSize = MaxReceivedMessageSize;
222 basicHttpBinding.MessageEncoding = MessageEncoding;
223 basicHttpBinding.ProxyAddress = ProxyAddress;
225 ReaderQuotas.ApplyConfiguration (basicHttpBinding.ReaderQuotas);
227 basicHttpBinding.Security.Mode = Security.Mode;
228 Security.Transport.ApplyConfiguration (basicHttpBinding.Security.Transport);
229 basicHttpBinding.TextEncoding = TextEncoding;
230 basicHttpBinding.TransferMode = TransferMode;
231 basicHttpBinding.UseDefaultWebProxy = UseDefaultWebProxy;
234 protected internal override void InitializeFrom (Binding binding)
236 BasicHttpBinding b = (BasicHttpBinding) binding;
238 base.InitializeFrom (binding);
239 AllowCookies = b.AllowCookies;
240 BypassProxyOnLocal = b.BypassProxyOnLocal;
241 HostNameComparisonMode = b.HostNameComparisonMode;
242 MaxBufferPoolSize = b.MaxBufferPoolSize;
243 MaxBufferSize = b.MaxBufferSize;
244 MaxReceivedMessageSize = b.MaxReceivedMessageSize;
245 MessageEncoding = b.MessageEncoding;
246 ProxyAddress = b.ProxyAddress;
248 ReaderQuotas.ApplyConfiguration (b.ReaderQuotas);
250 Security.Mode = b.Security.Mode;
251 Security.Transport.ApplyConfiguration (b.Security.Transport);
252 TextEncoding = b.TextEncoding;
253 TransferMode = b.TransferMode;
254 UseDefaultWebProxy = b.UseDefaultWebProxy;