Merge branch 'master' of github.com:mono/mono
[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.ServiceModel.Channels;
30 using System.Text;
31 using System.Xml;
32
33 namespace System.ServiceModel
34 {
35         public class WebHttpBinding
36 #if NET_2_1
37         : Binding
38 #else
39         : Binding, IBindingRuntimePreferences
40 #endif
41         {
42                 public WebHttpBinding ()
43                         : this (WebHttpSecurityMode.None)
44                 {
45                 }
46
47                 public WebHttpBinding (WebHttpSecurityMode mode)
48                 {
49                         security.Mode = mode;
50                         // MSDN says that this security mode can be set only
51                         // at .ctor(), so there is no problem on depending on
52                         // this value here.
53                         t = mode == WebHttpSecurityMode.Transport ? new HttpsTransportBindingElement () : new HttpTransportBindingElement ();
54                         t.ManualAddressing = true;
55                 }
56
57                 [MonoTODO]
58                 public WebHttpBinding (string configurationName)
59                 {
60                         throw new NotImplementedException ();
61                 }
62
63                 WebHttpSecurity security = new WebHttpSecurity ();
64                 HttpTransportBindingElement t;
65                 // This can be changed only using <synchronousReceive> configuration element.
66                 bool receive_synchronously;
67                 WebMessageEncodingBindingElement msgenc = new WebMessageEncodingBindingElement ();
68
69                 public EnvelopeVersion EnvelopeVersion {
70                         get { return EnvelopeVersion.None; }
71                 }
72
73 #if !NET_2_1
74                 public bool AllowCookies {
75                         get { return t.AllowCookies; }
76                         set { t.AllowCookies = value; }
77                 }
78
79                 public bool BypassProxyOnLocal {
80                         get { return t.BypassProxyOnLocal; }
81                         set { t.BypassProxyOnLocal = value; }
82                 }
83
84 #if NET_4_0
85                 [MonoTODO]
86                 public bool CrossDomainScriptAccessEnabled { get; set; }
87
88                 public WebContentTypeMapper ContentTypeMapper {
89                         get { return msgenc.ContentTypeMapper; }
90                         set { msgenc.ContentTypeMapper = value; }
91                 }
92 #endif
93
94                 public HostNameComparisonMode HostNameComparisonMode {
95                         get { return t.HostNameComparisonMode; }
96                         set { t.HostNameComparisonMode = value; }
97                 }
98
99                 public long MaxBufferPoolSize {
100                         get { return t.MaxBufferPoolSize; }
101                         set { t.MaxBufferPoolSize = value; }
102                 }
103
104                 public TransferMode TransferMode {
105                         get { return t.TransferMode; }
106                         set { t.TransferMode = value; }
107                 }
108
109                 public bool UseDefaultWebProxy {
110                         get { return t.UseDefaultWebProxy; }
111                         set { t.UseDefaultWebProxy = value; }
112                 }
113
114                 public Uri ProxyAddress {
115                         get { return t.ProxyAddress; }
116                         set { t.ProxyAddress = value; }
117                 }
118 #endif
119
120                 public int MaxBufferSize {
121                         get { return t.MaxBufferSize; }
122                         set { t.MaxBufferSize = value; }
123                 }
124
125                 public long MaxReceivedMessageSize {
126                         get { return t.MaxReceivedMessageSize; }
127                         set { t.MaxReceivedMessageSize = value; }
128                 }
129
130 #if !NET_2_1
131                 public XmlDictionaryReaderQuotas ReaderQuotas {
132                         get { return msgenc.ReaderQuotas; }
133                         set { msgenc.ReaderQuotas = value; }
134                 }
135 #endif
136
137                 public override string Scheme {
138                         get { return Security.Mode != WebHttpSecurityMode.None ? Uri.UriSchemeHttps : Uri.UriSchemeHttp; }
139                 }
140
141                 public WebHttpSecurity Security {
142                         get { return security; }
143                 }
144
145                 public Encoding WriteEncoding {
146                         get { return msgenc.WriteEncoding; }
147                         set {
148                                 if (value == null)
149                                         throw new ArgumentNullException ("value");
150                                 msgenc.WriteEncoding = value; 
151                         }
152                 }
153
154                 public override BindingElementCollection CreateBindingElements ()
155                 {
156                         return new BindingElementCollection (new BindingElement [] { msgenc, t.Clone () });
157                 }
158
159 #if !NET_2_1
160                 bool IBindingRuntimePreferences.ReceiveSynchronously {
161                         get { return receive_synchronously; }
162                 }
163 #endif
164         }
165 }