Add unit test for AggregateException.GetBaseException that works on .net but is broke...
[mono.git] / mcs / class / System.ServiceModel.Web / System.ServiceModel / WebHttpBinding.cs
1 //
2 // WebHttpBinding.cs
3 //
4 // Author:
5 //      Atsushi Enomoto  <atsushi@ximian.com>
6 //
7 // Copyright (C) 2008 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 using System;
29 using System.ComponentModel;
30 using System.Linq;
31 using System.ServiceModel.Channels;
32 using System.Text;
33 using System.Xml;
34 #if !NET_2_1
35 using System.Configuration;
36 using System.ServiceModel.Configuration;
37 #endif
38
39 namespace System.ServiceModel
40 {
41         public class WebHttpBinding
42 #if NET_2_1
43         : Binding
44 #else
45         : Binding, IBindingRuntimePreferences
46 #endif
47         {
48                 public WebHttpBinding ()
49                         : this (String.Empty)
50                 {
51                 }
52
53                 public WebHttpBinding (WebHttpSecurityMode mode)
54                 {
55                         Initialize (mode);
56                 }
57
58                 public WebHttpBinding (string configurationName)
59                 {
60 #if !NET_2_1
61                         BindingsSection bindingsSection = ConfigUtil.BindingsSection;
62                         WebHttpBindingElement el = (WebHttpBindingElement) bindingsSection ["webHttpBinding"].ConfiguredBindings.FirstOrDefault (c => c.Name == configurationName);
63                         if (el != null) {
64                                 Initialize (el.Security.Mode); // to initialize Transport correctly.
65                                 el.ApplyConfiguration (this);
66                         }
67                         else if (!String.IsNullOrEmpty (configurationName))
68                                 throw new ConfigurationException (String.Format ("Specified webHttpBinding configuration '{0}' was not found", configurationName));
69                         else
70                                 Initialize (WebHttpSecurityMode.None);
71 #else
72                         Initialize (WebHttpSecurityMode.None);
73 #endif
74                 }
75
76                 void Initialize (WebHttpSecurityMode mode)
77                 {
78                         security.Mode = mode;
79                         // MSDN says that this security mode can be set only
80                         // at .ctor(), so there is no problem on depending on
81                         // this value here.
82                         t = mode == WebHttpSecurityMode.Transport ? new HttpsTransportBindingElement () : new HttpTransportBindingElement ();
83                         t.ManualAddressing = true;
84                 }
85
86                 WebHttpSecurity security = new WebHttpSecurity ();
87                 HttpTransportBindingElement t;
88                 // This can be changed only using <synchronousReceive> configuration element.
89                 bool receive_synchronously;
90                 WebMessageEncodingBindingElement msgenc = new WebMessageEncodingBindingElement ();
91
92                 public EnvelopeVersion EnvelopeVersion {
93                         get { return EnvelopeVersion.None; }
94                 }
95
96 #if !NET_2_1
97 #if NET_4_0
98                 [DefaultValue (false)]
99 #endif
100                 public bool AllowCookies {
101                         get { return t.AllowCookies; }
102                         set { t.AllowCookies = value; }
103                 }
104
105 #if NET_4_0
106                 [DefaultValue (false)]
107 #endif
108                 public bool BypassProxyOnLocal {
109                         get { return t.BypassProxyOnLocal; }
110                         set { t.BypassProxyOnLocal = value; }
111                 }
112
113 #if NET_4_0
114                 [MonoTODO]
115                 public bool CrossDomainScriptAccessEnabled { get; set; }
116
117                 public WebContentTypeMapper ContentTypeMapper {
118                         get { return msgenc.ContentTypeMapper; }
119                         set { msgenc.ContentTypeMapper = value; }
120                 }
121 #endif
122
123 #if NET_4_0
124                 [DefaultValue (HostNameComparisonMode.StrongWildcard)]
125 #endif
126                 public HostNameComparisonMode HostNameComparisonMode {
127                         get { return t.HostNameComparisonMode; }
128                         set { t.HostNameComparisonMode = value; }
129                 }
130
131 #if NET_4_0
132                 [DefaultValue (0x10000)]
133 #endif
134                 public long MaxBufferPoolSize {
135                         get { return t.MaxBufferPoolSize; }
136                         set { t.MaxBufferPoolSize = value; }
137                 }
138
139 #if NET_4_0
140                 [DefaultValue (TransferMode.Buffered)]
141 #endif
142                 public TransferMode TransferMode {
143                         get { return t.TransferMode; }
144                         set { t.TransferMode = value; }
145                 }
146
147 #if NET_4_0
148                 [DefaultValue (true)]
149 #endif
150                 public bool UseDefaultWebProxy {
151                         get { return t.UseDefaultWebProxy; }
152                         set { t.UseDefaultWebProxy = value; }
153                 }
154
155 #if NET_4_0
156                 [DefaultValue (null)]
157 #endif
158                 public Uri ProxyAddress {
159                         get { return t.ProxyAddress; }
160                         set { t.ProxyAddress = value; }
161                 }
162 #endif
163
164 #if NET_4_0
165                 [DefaultValue (0x80000)]
166 #endif
167                 public int MaxBufferSize {
168                         get { return t.MaxBufferSize; }
169                         set { t.MaxBufferSize = value; }
170                 }
171
172 #if NET_4_0
173                 [DefaultValue (0x10000)]
174 #endif
175                 public long MaxReceivedMessageSize {
176                         get { return t.MaxReceivedMessageSize; }
177                         set { t.MaxReceivedMessageSize = value; }
178                 }
179
180                 public XmlDictionaryReaderQuotas ReaderQuotas {
181                         get { return msgenc.ReaderQuotas; }
182                         set { msgenc.ReaderQuotas = value; }
183                 }
184
185                 public override string Scheme {
186                         get { return Security.Mode != WebHttpSecurityMode.None ? Uri.UriSchemeHttps : Uri.UriSchemeHttp; }
187                 }
188
189                 public WebHttpSecurity Security {
190                         get { return security; }
191 #if NET_4_0
192                         set {
193                                 if (value == null)
194                                         throw new ArgumentNullException ("value");
195                                 security = value;
196                         }
197 #endif
198                 }
199
200                 public Encoding WriteEncoding {
201                         get { return msgenc.WriteEncoding; }
202                         set {
203                                 if (value == null)
204                                         throw new ArgumentNullException ("value");
205                                 msgenc.WriteEncoding = value; 
206                         }
207                 }
208
209                 public override BindingElementCollection CreateBindingElements ()
210                 {
211                         return new BindingElementCollection (new BindingElement [] { msgenc, t.Clone () });
212                 }
213
214 #if !NET_2_1
215                 bool IBindingRuntimePreferences.ReceiveSynchronously {
216                         get { return receive_synchronously; }
217                 }
218 #endif
219
220 #if NET_4_0
221                 [EditorBrowsable (EditorBrowsableState.Advanced)]
222                 public bool ShouldSerializeReaderQuotas ()
223                 {
224                         return false;
225                 }
226                 
227                 [EditorBrowsable (EditorBrowsableState.Advanced)]
228                 public bool ShouldSerializeSecurity ()
229                 {
230                         return false;
231                 }
232                 
233                 [EditorBrowsable (EditorBrowsableState.Advanced)]
234                 public bool ShouldSerializeWriteEncoding ()
235                 {
236                         return false;
237                 }
238 #endif
239         }
240 }