Fix null sessions in HttpContextWrapper.Session
[mono.git] / mcs / class / System.ServiceModel / System.ServiceModel.Configuration / BasicHttpBindingElement.cs
1 //
2 // BasicHttpBindingElement.cs
3 //
4 // Author:
5 //      Atsushi Enomoto <atsushi@ximian.com>
6 //
7 // Copyright (C) 2006 Novell, Inc.  http://www.novell.com
8 //
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:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
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.
27 //
28
29 using System;
30 using System.Collections;
31 using System.Collections.Generic;
32 using System.Collections.ObjectModel;
33 using System.ComponentModel;
34 using System.Configuration;
35 using System.Net;
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;
52 using System.Text;
53 using System.Xml;
54
55 namespace System.ServiceModel.Configuration
56 {
57         public class BasicHttpBindingElement
58                  : StandardBindingElement,  IBindingConfigurationElement
59         {
60                 ConfigurationPropertyCollection _properties;
61
62                 public BasicHttpBindingElement ()
63                 {
64                 }
65
66                 public BasicHttpBindingElement (string name) : base (name) { }
67
68                 // Properties
69
70                 [ConfigurationProperty ("allowCookies",
71                         DefaultValue = false,
72                          Options = ConfigurationPropertyOptions.None)]
73                 public bool AllowCookies {
74                         get { return (bool) this ["allowCookies"]; }
75                         set { this ["allowCookies"] = value; }
76                 }
77
78                 protected override Type BindingElementType {
79                         get { return typeof (BasicHttpBinding); }
80                 }
81
82                 [ConfigurationProperty ("bypassProxyOnLocal",
83                         DefaultValue = false,
84                          Options = ConfigurationPropertyOptions.None)]
85                 public bool BypassProxyOnLocal {
86                         get { return (bool) this ["bypassProxyOnLocal"]; }
87                         set { this ["bypassProxyOnLocal"] = value; }
88                 }
89
90                 [ConfigurationProperty ("hostNameComparisonMode",
91                          DefaultValue = "StrongWildcard",
92                          Options = ConfigurationPropertyOptions.None)]
93                 public HostNameComparisonMode HostNameComparisonMode {
94                         get { return (HostNameComparisonMode) this ["hostNameComparisonMode"]; }
95                         set { this ["hostNameComparisonMode"] = value; }
96                 }
97
98                 [LongValidator ( MinValue = 0,
99                          MaxValue = 9223372036854775807,
100                         ExcludeRange = false)]
101                 [ConfigurationProperty ("maxBufferPoolSize",
102                          DefaultValue = "524288",
103                          Options = ConfigurationPropertyOptions.None)]
104                 public long MaxBufferPoolSize {
105                         get { return (long) this ["maxBufferPoolSize"]; }
106                         set { this ["maxBufferPoolSize"] = value; }
107                 }
108
109                 [IntegerValidator ( MinValue = 1,
110                         MaxValue = int.MaxValue,
111                         ExcludeRange = false)]
112                 [ConfigurationProperty ("maxBufferSize",
113                          DefaultValue = "65536",
114                          Options = ConfigurationPropertyOptions.None)]
115                 public int MaxBufferSize {
116                         get { return (int) this ["maxBufferSize"]; }
117                         set { this ["maxBufferSize"] = value; }
118                 }
119
120                 [LongValidator ( MinValue = 1,
121                          MaxValue = 9223372036854775807,
122                         ExcludeRange = false)]
123                 [ConfigurationProperty ("maxReceivedMessageSize",
124                          DefaultValue = "65536",
125                          Options = ConfigurationPropertyOptions.None)]
126                 public long MaxReceivedMessageSize {
127                         get { return (long) this ["maxReceivedMessageSize"]; }
128                         set { this ["maxReceivedMessageSize"] = value; }
129                 }
130
131                 [ConfigurationProperty ("messageEncoding",
132                          DefaultValue = "Text",
133                          Options = ConfigurationPropertyOptions.None)]
134                 public WSMessageEncoding MessageEncoding {
135                         get { return (WSMessageEncoding) this ["messageEncoding"]; }
136                         set { this ["messageEncoding"] = value; }
137                 }
138
139                 protected override ConfigurationPropertyCollection Properties {
140                         get {
141                                 if (_properties == null) {
142                                         _properties = base.Properties;
143                                         _properties.Add (new ConfigurationProperty ("allowCookies", typeof (bool), "false", null, null, ConfigurationPropertyOptions.None));
144                                         _properties.Add (new ConfigurationProperty ("bypassProxyOnLocal", typeof (bool), "false", null, null, ConfigurationPropertyOptions.None));
145                                         _properties.Add (new ConfigurationProperty ("hostNameComparisonMode", typeof (HostNameComparisonMode), "StrongWildcard", null, null, ConfigurationPropertyOptions.None));
146                                         _properties.Add (new ConfigurationProperty ("maxBufferPoolSize", typeof (long), "524288", null, new LongValidator (0, 9223372036854775807, false), ConfigurationPropertyOptions.None));
147                                         _properties.Add (new ConfigurationProperty ("maxBufferSize", typeof (int), "65536", null, new IntegerValidator (1, int.MaxValue, false), ConfigurationPropertyOptions.None));
148                                         _properties.Add (new ConfigurationProperty ("maxReceivedMessageSize", typeof (long), "65536", null, new LongValidator (1, 9223372036854775807, false), ConfigurationPropertyOptions.None));
149                                         _properties.Add (new ConfigurationProperty ("messageEncoding", typeof (WSMessageEncoding), "Text", null, null, ConfigurationPropertyOptions.None));
150                                         _properties.Add (new ConfigurationProperty ("proxyAddress", typeof (Uri), null, new UriTypeConverter (), null, ConfigurationPropertyOptions.None));
151                                         _properties.Add (new ConfigurationProperty ("readerQuotas", typeof (XmlDictionaryReaderQuotasElement), null, null, null, ConfigurationPropertyOptions.None));
152                                         _properties.Add (new ConfigurationProperty ("security", typeof (BasicHttpSecurityElement), null, null, null, ConfigurationPropertyOptions.None));
153                                         _properties.Add (new ConfigurationProperty ("textEncoding", typeof (Encoding), "utf-8", EncodingConverter.Instance, null, ConfigurationPropertyOptions.None));
154                                         _properties.Add (new ConfigurationProperty ("transferMode", typeof (TransferMode), "Buffered", null, null, ConfigurationPropertyOptions.None));
155                                         _properties.Add (new ConfigurationProperty ("useDefaultWebProxy", typeof (bool), "true", new BooleanConverter (), null, ConfigurationPropertyOptions.None));
156                                 }
157                                 return _properties;
158                         }
159                 }
160
161                 [ConfigurationProperty ("proxyAddress",
162                          DefaultValue = null,
163                          Options = ConfigurationPropertyOptions.None)]
164                 public Uri ProxyAddress {
165                         get { return (Uri) this ["proxyAddress"]; }
166                         set { this ["proxyAddress"] = value; }
167                 }
168
169                 [ConfigurationProperty ("readerQuotas",
170                          Options = ConfigurationPropertyOptions.None)]
171                 public XmlDictionaryReaderQuotasElement ReaderQuotas {
172                         get { return (XmlDictionaryReaderQuotasElement) this ["readerQuotas"]; }
173                 }
174
175                 [ConfigurationProperty ("security",
176                          Options = ConfigurationPropertyOptions.None)]
177                 public BasicHttpSecurityElement Security {
178                         get { return (BasicHttpSecurityElement) this ["security"]; }
179                 }
180
181                 [TypeConverter (typeof (EncodingConverter))]
182                 [ConfigurationProperty ("textEncoding",
183                          DefaultValue = "utf-8",
184                          Options = ConfigurationPropertyOptions.None)]
185                 public Encoding TextEncoding {
186                         get { return (Encoding) this ["textEncoding"]; }
187                         set { this ["textEncoding"] = value; }
188                 }
189
190                 [ConfigurationProperty ("transferMode",
191                          DefaultValue = "Buffered",
192                          Options = ConfigurationPropertyOptions.None)]
193                 public TransferMode TransferMode {
194                         get { return (TransferMode) this ["transferMode"]; }
195                         set { this ["transferMode"] = value; }
196                 }
197
198                 [ConfigurationProperty ("useDefaultWebProxy",
199                         DefaultValue = true,
200                          Options = ConfigurationPropertyOptions.None)]
201                 public bool UseDefaultWebProxy {
202                         get { return (bool) this ["useDefaultWebProxy"]; }
203                         set { this ["useDefaultWebProxy"] = value; }
204                 }
205
206                 protected override void OnApplyConfiguration (Binding binding)
207                 {
208                         BasicHttpBinding basicHttpBinding = (BasicHttpBinding) binding;
209                         
210                         basicHttpBinding.AllowCookies = AllowCookies;
211                         basicHttpBinding.BypassProxyOnLocal = BypassProxyOnLocal;
212                         basicHttpBinding.HostNameComparisonMode = HostNameComparisonMode;
213                         basicHttpBinding.MaxBufferPoolSize = MaxBufferPoolSize;
214                         basicHttpBinding.MaxBufferSize = MaxBufferSize;
215                         basicHttpBinding.MaxReceivedMessageSize = MaxReceivedMessageSize;
216                         basicHttpBinding.MessageEncoding = MessageEncoding;
217                         basicHttpBinding.ProxyAddress = ProxyAddress;
218
219                         ReaderQuotas.ApplyConfiguration (basicHttpBinding.ReaderQuotas);
220
221                         basicHttpBinding.Security.Mode = Security.Mode;
222                         Security.Transport.ApplyConfiguration (basicHttpBinding.Security.Transport);
223                         basicHttpBinding.TextEncoding = TextEncoding;
224                         basicHttpBinding.TransferMode = TransferMode;
225                         basicHttpBinding.UseDefaultWebProxy = UseDefaultWebProxy;
226                 }
227
228                 protected internal override void InitializeFrom (Binding binding)
229                 {
230                         BasicHttpBinding b = (BasicHttpBinding) binding;
231                         
232                         base.InitializeFrom (binding);
233                         AllowCookies = b.AllowCookies;
234                         BypassProxyOnLocal = b.BypassProxyOnLocal;
235                         HostNameComparisonMode = b.HostNameComparisonMode;
236                         MaxBufferPoolSize = b.MaxBufferPoolSize;
237                         MaxBufferSize = b.MaxBufferSize;
238                         MaxReceivedMessageSize = b.MaxReceivedMessageSize;
239                         MessageEncoding = b.MessageEncoding;
240                         ProxyAddress = b.ProxyAddress;
241
242                         ReaderQuotas.ApplyConfiguration (b.ReaderQuotas);
243
244                         Security.Mode = b.Security.Mode;
245                         Security.Transport.ApplyConfiguration (b.Security.Transport);
246                         TextEncoding = b.TextEncoding;
247                         TransferMode = b.TransferMode;
248                         UseDefaultWebProxy = b.UseDefaultWebProxy;
249                 }
250         }
251
252 }