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.
29 using System.ComponentModel;
31 using System.ServiceModel.Channels;
35 using System.Configuration;
36 using System.ServiceModel.Configuration;
39 namespace System.ServiceModel
41 public class WebHttpBinding : Binding, IBindingRuntimePreferences
43 public WebHttpBinding ()
48 public WebHttpBinding (WebHttpSecurityMode mode)
53 public WebHttpBinding (string configurationName)
56 BindingsSection bindingsSection = ConfigUtil.BindingsSection;
57 WebHttpBindingElement el = (WebHttpBindingElement) bindingsSection ["webHttpBinding"].ConfiguredBindings.FirstOrDefault (c => c.Name == configurationName);
59 Initialize (el.Security.Mode); // to initialize Transport correctly.
60 el.ApplyConfiguration (this);
62 else if (!String.IsNullOrEmpty (configurationName))
63 throw new ConfigurationException (String.Format ("Specified webHttpBinding configuration '{0}' was not found", configurationName));
65 Initialize (WebHttpSecurityMode.None);
67 Initialize (WebHttpSecurityMode.None);
71 void Initialize (WebHttpSecurityMode mode)
74 // MSDN says that this security mode can be set only
75 // at .ctor(), so there is no problem on depending on
77 t = mode == WebHttpSecurityMode.Transport ? new HttpsTransportBindingElement () : new HttpTransportBindingElement ();
78 t.ManualAddressing = true;
81 WebHttpSecurity security = new WebHttpSecurity ();
82 HttpTransportBindingElement t;
83 // This can be changed only using <synchronousReceive> configuration element.
84 bool receive_synchronously;
85 WebMessageEncodingBindingElement msgenc = new WebMessageEncodingBindingElement ();
87 public EnvelopeVersion EnvelopeVersion {
88 get { return EnvelopeVersion.None; }
93 [DefaultValue (false)]
95 public bool AllowCookies {
96 get { return t.AllowCookies; }
97 set { t.AllowCookies = value; }
101 [DefaultValue (false)]
103 public bool BypassProxyOnLocal {
104 get { return t.BypassProxyOnLocal; }
105 set { t.BypassProxyOnLocal = value; }
110 public bool CrossDomainScriptAccessEnabled { get; set; }
112 public WebContentTypeMapper ContentTypeMapper {
113 get { return msgenc.ContentTypeMapper; }
114 set { msgenc.ContentTypeMapper = value; }
119 [DefaultValue (HostNameComparisonMode.StrongWildcard)]
121 public HostNameComparisonMode HostNameComparisonMode {
122 get { return t.HostNameComparisonMode; }
123 set { t.HostNameComparisonMode = value; }
127 [DefaultValue (0x10000)]
129 public long MaxBufferPoolSize {
130 get { return t.MaxBufferPoolSize; }
131 set { t.MaxBufferPoolSize = value; }
135 [DefaultValue (TransferMode.Buffered)]
137 public TransferMode TransferMode {
138 get { return t.TransferMode; }
139 set { t.TransferMode = value; }
143 [DefaultValue (true)]
145 public bool UseDefaultWebProxy {
146 get { return t.UseDefaultWebProxy; }
147 set { t.UseDefaultWebProxy = value; }
151 [DefaultValue (null)]
153 public Uri ProxyAddress {
154 get { return t.ProxyAddress; }
155 set { t.ProxyAddress = value; }
160 [DefaultValue (0x80000)]
162 public int MaxBufferSize {
163 get { return t.MaxBufferSize; }
164 set { t.MaxBufferSize = value; }
168 [DefaultValue (0x10000)]
170 public long MaxReceivedMessageSize {
171 get { return t.MaxReceivedMessageSize; }
172 set { t.MaxReceivedMessageSize = value; }
175 public XmlDictionaryReaderQuotas ReaderQuotas {
176 get { return msgenc.ReaderQuotas; }
177 set { msgenc.ReaderQuotas = value; }
180 public override string Scheme {
181 get { return Security.Mode != WebHttpSecurityMode.None ? Uri.UriSchemeHttps : Uri.UriSchemeHttp; }
184 public WebHttpSecurity Security {
185 get { return security; }
189 throw new ArgumentNullException ("value");
195 public Encoding WriteEncoding {
196 get { return msgenc.WriteEncoding; }
199 throw new ArgumentNullException ("value");
200 msgenc.WriteEncoding = value;
204 public override BindingElementCollection CreateBindingElements ()
206 return new BindingElementCollection (new BindingElement [] { msgenc, t.Clone () });
209 bool IBindingRuntimePreferences.ReceiveSynchronously {
210 get { return receive_synchronously; }
214 [EditorBrowsable (EditorBrowsableState.Advanced)]
215 public bool ShouldSerializeReaderQuotas ()
220 [EditorBrowsable (EditorBrowsableState.Advanced)]
221 public bool ShouldSerializeSecurity ()
226 [EditorBrowsable (EditorBrowsableState.Advanced)]
227 public bool ShouldSerializeWriteEncoding ()