2 // WebHttpBindingElement.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2008 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.ServiceModel;
39 using System.ServiceModel.Channels;
40 using System.ServiceModel.Description;
41 using System.ServiceModel.Diagnostics;
42 using System.ServiceModel.Dispatcher;
43 using System.Runtime.Serialization;
47 namespace System.ServiceModel.Configuration
49 public partial class WebHttpBindingElement
50 : StandardBindingElement, IBindingConfigurationElement
53 static bool base_merged;
54 static ConfigurationPropertyCollection properties;
55 static ConfigurationProperty allow_cookies;
56 static ConfigurationProperty bypass_proxy_on_local;
57 static ConfigurationProperty host_name_comparison_mode;
58 static ConfigurationProperty max_buffer_pool_size;
59 static ConfigurationProperty max_buffer_size;
60 static ConfigurationProperty max_received_message_size;
61 static ConfigurationProperty proxy_address;
62 static ConfigurationProperty reader_quotas;
63 static ConfigurationProperty security;
64 static ConfigurationProperty write_encoding;
65 static ConfigurationProperty transfer_mode;
66 static ConfigurationProperty use_default_web_proxy;
68 static WebHttpBindingElement ()
70 properties = new ConfigurationPropertyCollection ();
71 allow_cookies = new ConfigurationProperty ("allowCookies",
72 typeof (bool), "false", new BooleanConverter (), null,
73 ConfigurationPropertyOptions.None);
75 bypass_proxy_on_local = new ConfigurationProperty ("bypassProxyOnLocal",
76 typeof (bool), "false", new BooleanConverter (), null,
77 ConfigurationPropertyOptions.None);
79 host_name_comparison_mode = new ConfigurationProperty ("hostNameComparisonMode",
80 typeof (HostNameComparisonMode), "StrongWildcard", null/* FIXME: get converter for HostNameComparisonMode*/, null,
81 ConfigurationPropertyOptions.None);
83 max_buffer_pool_size = new ConfigurationProperty ("maxBufferPoolSize",
84 typeof (long), "524288", new Int64Converter (), null,
85 ConfigurationPropertyOptions.None);
87 max_buffer_size = new ConfigurationProperty ("maxBufferSize",
88 typeof (int), "65536", new Int32Converter (), null,
89 ConfigurationPropertyOptions.None);
91 max_received_message_size = new ConfigurationProperty ("maxReceivedMessageSize",
92 typeof (long), "65536", new Int64Converter (), null,
93 ConfigurationPropertyOptions.None);
95 proxy_address = new ConfigurationProperty ("proxyAddress",
96 typeof (Uri), null, new UriTypeConverter (), null,
97 ConfigurationPropertyOptions.None);
99 reader_quotas = new ConfigurationProperty ("readerQuotas",
100 typeof (XmlDictionaryReaderQuotasElement), null, null/* FIXME: get converter for XmlDictionaryReaderQuotasElement*/, null,
101 ConfigurationPropertyOptions.None);
103 security = new ConfigurationProperty ("security",
104 typeof (WebHttpSecurityElement), null, null/* FIXME: get converter for WebHttpSecurityElement*/, null,
105 ConfigurationPropertyOptions.None);
107 write_encoding = new ConfigurationProperty ("writeEncoding",
108 typeof (Encoding), "utf-8", new EncodingConverter (), null,
109 ConfigurationPropertyOptions.None);
111 transfer_mode = new ConfigurationProperty ("transferMode",
112 typeof (TransferMode), "Buffered", null/* FIXME: get converter for TransferMode*/, null,
113 ConfigurationPropertyOptions.None);
115 use_default_web_proxy = new ConfigurationProperty ("useDefaultWebProxy",
116 typeof (bool), "true", new BooleanConverter (), null,
117 ConfigurationPropertyOptions.None);
119 properties.Add (allow_cookies);
120 properties.Add (bypass_proxy_on_local);
121 properties.Add (host_name_comparison_mode);
122 properties.Add (max_buffer_pool_size);
123 properties.Add (max_buffer_size);
124 properties.Add (max_received_message_size);
125 properties.Add (proxy_address);
126 properties.Add (reader_quotas);
127 properties.Add (security);
128 properties.Add (write_encoding);
129 properties.Add (transfer_mode);
130 properties.Add (use_default_web_proxy);
133 public WebHttpBindingElement ()
137 public WebHttpBindingElement (string name)
144 [ConfigurationProperty ("allowCookies",
145 DefaultValue = false,
146 Options = ConfigurationPropertyOptions.None)]
147 public bool AllowCookies {
148 get { return (bool) base [allow_cookies]; }
149 set { base [allow_cookies] = value; }
152 protected override Type BindingElementType {
153 get { return typeof (WebHttpBinding); }
156 [ConfigurationProperty ("bypassProxyOnLocal",
157 DefaultValue = false,
158 Options = ConfigurationPropertyOptions.None)]
159 public bool BypassProxyOnLocal {
160 get { return (bool) base [bypass_proxy_on_local]; }
161 set { base [bypass_proxy_on_local] = value; }
164 [ConfigurationProperty ("hostNameComparisonMode",
165 DefaultValue = "StrongWildcard",
166 Options = ConfigurationPropertyOptions.None)]
167 public HostNameComparisonMode HostNameComparisonMode {
168 get { return (HostNameComparisonMode) base [host_name_comparison_mode]; }
169 set { base [host_name_comparison_mode] = value; }
172 [LongValidator ( MinValue = 0,
173 MaxValue = 9223372036854775807,
174 ExcludeRange = false)]
175 [ConfigurationProperty ("maxBufferPoolSize",
176 DefaultValue = "524288",
177 Options = ConfigurationPropertyOptions.None)]
178 public long MaxBufferPoolSize {
179 get { return (long) base [max_buffer_pool_size]; }
180 set { base [max_buffer_pool_size] = value; }
183 [IntegerValidator ( MinValue = 1,
184 MaxValue = int.MaxValue,
185 ExcludeRange = false)]
186 [ConfigurationProperty ("maxBufferSize",
187 DefaultValue = "65536",
188 Options = ConfigurationPropertyOptions.None)]
189 public int MaxBufferSize {
190 get { return (int) base [max_buffer_size]; }
191 set { base [max_buffer_size] = value; }
194 [LongValidator ( MinValue = 1,
195 MaxValue = 9223372036854775807,
196 ExcludeRange = false)]
197 [ConfigurationProperty ("maxReceivedMessageSize",
198 DefaultValue = "65536",
199 Options = ConfigurationPropertyOptions.None)]
200 public long MaxReceivedMessageSize {
201 get { return (long) base [max_received_message_size]; }
202 set { base [max_received_message_size] = value; }
205 protected override ConfigurationPropertyCollection Properties {
210 foreach (ConfigurationProperty p in base.Properties)
218 [ConfigurationProperty ("proxyAddress",
220 Options = ConfigurationPropertyOptions.None)]
221 public Uri ProxyAddress {
222 get { return (Uri) base [proxy_address]; }
223 set { base [proxy_address] = value; }
226 [ConfigurationProperty ("readerQuotas",
227 Options = ConfigurationPropertyOptions.None)]
228 public XmlDictionaryReaderQuotasElement ReaderQuotas {
229 get { return (XmlDictionaryReaderQuotasElement) base [reader_quotas]; }
232 [ConfigurationProperty ("security",
233 Options = ConfigurationPropertyOptions.None)]
234 public WebHttpSecurityElement Security {
235 get { return (WebHttpSecurityElement) base [security]; }
239 [ConfigurationProperty ("writeEncoding",
240 DefaultValue = "utf-8",
241 Options = ConfigurationPropertyOptions.None)]
242 public Encoding WriteEncoding {
243 get { return (Encoding) base [write_encoding]; }
244 set { base [write_encoding] = value; }
247 [ConfigurationProperty ("transferMode",
248 DefaultValue = "Buffered",
249 Options = ConfigurationPropertyOptions.None)]
250 public TransferMode TransferMode {
251 get { return (TransferMode) base [transfer_mode]; }
252 set { base [transfer_mode] = value; }
255 [ConfigurationProperty ("useDefaultWebProxy",
257 Options = ConfigurationPropertyOptions.None)]
258 public bool UseDefaultWebProxy {
259 get { return (bool) base [use_default_web_proxy]; }
260 set { base [use_default_web_proxy] = value; }
263 protected override void OnApplyConfiguration (Binding binding)
265 WebHttpBinding webBinding = (WebHttpBinding)binding;
267 webBinding.AllowCookies = AllowCookies;
268 webBinding.BypassProxyOnLocal = BypassProxyOnLocal;
269 webBinding.HostNameComparisonMode = HostNameComparisonMode;
270 webBinding.MaxBufferPoolSize = MaxBufferPoolSize;
271 webBinding.MaxBufferSize = MaxBufferSize;
272 webBinding.MaxReceivedMessageSize = MaxReceivedMessageSize;
273 if(ProxyAddress != null)
274 webBinding.ProxyAddress = ProxyAddress;
275 webBinding.TransferMode = TransferMode;
276 webBinding.UseDefaultWebProxy = UseDefaultWebProxy;
277 webBinding.WriteEncoding = WriteEncoding;
279 Security.ApplyConfiguration (webBinding.Security);
282 protected internal override void InitializeFrom (Binding binding)
284 WebHttpBinding b = (WebHttpBinding)binding;
286 AllowCookies = b.AllowCookies;
287 BypassProxyOnLocal = b.BypassProxyOnLocal;
288 HostNameComparisonMode = b.HostNameComparisonMode;
289 MaxBufferPoolSize = b.MaxBufferPoolSize;
290 MaxBufferSize = b.MaxBufferSize;
291 MaxReceivedMessageSize = b.MaxReceivedMessageSize;
292 if(ProxyAddress != null)
293 ProxyAddress = b.ProxyAddress;
294 TransferMode = b.TransferMode;
295 UseDefaultWebProxy = b.UseDefaultWebProxy;
296 WriteEncoding = b.WriteEncoding;
298 Security.InitializeFrom (b.Security);