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)
55 #if !MOBILE && !XAMMAC_4_5
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; }
91 #if !MOBILE && !XAMMAC_4_5
92 [DefaultValue (false)]
93 public bool AllowCookies {
94 get { return t.AllowCookies; }
95 set { t.AllowCookies = value; }
98 [DefaultValue (false)]
99 public bool BypassProxyOnLocal {
100 get { return t.BypassProxyOnLocal; }
101 set { t.BypassProxyOnLocal = value; }
105 public bool CrossDomainScriptAccessEnabled { get; set; }
107 public WebContentTypeMapper ContentTypeMapper {
108 get { return msgenc.ContentTypeMapper; }
109 set { msgenc.ContentTypeMapper = value; }
112 [DefaultValue (HostNameComparisonMode.StrongWildcard)]
113 public HostNameComparisonMode HostNameComparisonMode {
114 get { return t.HostNameComparisonMode; }
115 set { t.HostNameComparisonMode = value; }
118 [DefaultValue (0x10000)]
119 public long MaxBufferPoolSize {
120 get { return t.MaxBufferPoolSize; }
121 set { t.MaxBufferPoolSize = value; }
124 [DefaultValue (TransferMode.Buffered)]
125 public TransferMode TransferMode {
126 get { return t.TransferMode; }
127 set { t.TransferMode = value; }
130 [DefaultValue (true)]
131 public bool UseDefaultWebProxy {
132 get { return t.UseDefaultWebProxy; }
133 set { t.UseDefaultWebProxy = value; }
136 [DefaultValue (null)]
137 public Uri ProxyAddress {
138 get { return t.ProxyAddress; }
139 set { t.ProxyAddress = value; }
143 [DefaultValue (0x80000)]
144 public int MaxBufferSize {
145 get { return t.MaxBufferSize; }
146 set { t.MaxBufferSize = value; }
149 [DefaultValue (0x10000)]
150 public long MaxReceivedMessageSize {
151 get { return t.MaxReceivedMessageSize; }
152 set { t.MaxReceivedMessageSize = value; }
155 public XmlDictionaryReaderQuotas ReaderQuotas {
156 get { return msgenc.ReaderQuotas; }
157 set { msgenc.ReaderQuotas = value; }
160 public override string Scheme {
161 get { return Security.Mode == WebHttpSecurityMode.Transport ? Uri.UriSchemeHttps : Uri.UriSchemeHttp; }
164 public WebHttpSecurity Security {
165 get { return security; }
168 throw new ArgumentNullException ("value");
173 public Encoding WriteEncoding {
174 get { return msgenc.WriteEncoding; }
177 throw new ArgumentNullException ("value");
178 msgenc.WriteEncoding = value;
182 public override BindingElementCollection CreateBindingElements ()
184 return new BindingElementCollection (new BindingElement [] { msgenc, t.Clone () });
187 bool IBindingRuntimePreferences.ReceiveSynchronously {
188 get { return receive_synchronously; }
191 [EditorBrowsable (EditorBrowsableState.Advanced)]
192 public bool ShouldSerializeReaderQuotas ()
197 [EditorBrowsable (EditorBrowsableState.Advanced)]
198 public bool ShouldSerializeSecurity ()
203 [EditorBrowsable (EditorBrowsableState.Advanced)]
204 public bool ShouldSerializeWriteEncoding ()