//
using System;
using System.ComponentModel;
+using System.Linq;
using System.ServiceModel.Channels;
using System.Text;
using System.Xml;
+#if !MOBILE
+using System.Configuration;
+using System.ServiceModel.Configuration;
+#endif
namespace System.ServiceModel
{
- public class WebHttpBinding
-#if NET_2_1
- : Binding
-#else
- : Binding, IBindingRuntimePreferences
-#endif
+ public class WebHttpBinding : Binding, IBindingRuntimePreferences
{
public WebHttpBinding ()
- : this (WebHttpSecurityMode.None)
+ : this (String.Empty)
+ {
+ }
+
+ public WebHttpBinding (WebHttpSecurityMode securityMode)
+ {
+ Initialize (securityMode);
+ }
+
+ public WebHttpBinding (string configurationName)
{
+#if !MOBILE && !XAMMAC_4_5
+ BindingsSection bindingsSection = ConfigUtil.BindingsSection;
+ WebHttpBindingElement el = (WebHttpBindingElement) bindingsSection ["webHttpBinding"].ConfiguredBindings.FirstOrDefault (c => c.Name == configurationName);
+ if (el != null) {
+ Initialize (el.Security.Mode); // to initialize Transport correctly.
+ el.ApplyConfiguration (this);
+ }
+ else if (!String.IsNullOrEmpty (configurationName))
+ throw new ConfigurationException (String.Format ("Specified webHttpBinding configuration '{0}' was not found", configurationName));
+ else
+ Initialize (WebHttpSecurityMode.None);
+#else
+ Initialize (WebHttpSecurityMode.None);
+#endif
}
- public WebHttpBinding (WebHttpSecurityMode mode)
+ void Initialize (WebHttpSecurityMode mode)
{
security.Mode = mode;
// MSDN says that this security mode can be set only
t.ManualAddressing = true;
}
- [MonoTODO]
- public WebHttpBinding (string configurationName)
- {
- throw new NotImplementedException ();
- }
-
WebHttpSecurity security = new WebHttpSecurity ();
HttpTransportBindingElement t;
// This can be changed only using <synchronousReceive> configuration element.
- bool receive_synchronously;
WebMessageEncodingBindingElement msgenc = new WebMessageEncodingBindingElement ();
public EnvelopeVersion EnvelopeVersion {
get { return EnvelopeVersion.None; }
}
-#if !NET_2_1
-#if NET_4_0
+#if !MOBILE && !XAMMAC_4_5
[DefaultValue (false)]
-#endif
public bool AllowCookies {
get { return t.AllowCookies; }
set { t.AllowCookies = value; }
}
-#if NET_4_0
[DefaultValue (false)]
-#endif
public bool BypassProxyOnLocal {
get { return t.BypassProxyOnLocal; }
set { t.BypassProxyOnLocal = value; }
}
-#if NET_4_0
[MonoTODO]
public bool CrossDomainScriptAccessEnabled { get; set; }
get { return msgenc.ContentTypeMapper; }
set { msgenc.ContentTypeMapper = value; }
}
-#endif
-#if NET_4_0
[DefaultValue (HostNameComparisonMode.StrongWildcard)]
-#endif
public HostNameComparisonMode HostNameComparisonMode {
get { return t.HostNameComparisonMode; }
set { t.HostNameComparisonMode = value; }
}
-#if NET_4_0
[DefaultValue (0x10000)]
-#endif
public long MaxBufferPoolSize {
get { return t.MaxBufferPoolSize; }
set { t.MaxBufferPoolSize = value; }
}
-#if NET_4_0
[DefaultValue (TransferMode.Buffered)]
-#endif
public TransferMode TransferMode {
get { return t.TransferMode; }
set { t.TransferMode = value; }
}
-#if NET_4_0
[DefaultValue (true)]
-#endif
public bool UseDefaultWebProxy {
get { return t.UseDefaultWebProxy; }
set { t.UseDefaultWebProxy = value; }
}
-#if NET_4_0
[DefaultValue (null)]
-#endif
public Uri ProxyAddress {
get { return t.ProxyAddress; }
set { t.ProxyAddress = value; }
}
#endif
-#if NET_4_0
[DefaultValue (0x80000)]
-#endif
public int MaxBufferSize {
get { return t.MaxBufferSize; }
set { t.MaxBufferSize = value; }
}
-#if NET_4_0
[DefaultValue (0x10000)]
-#endif
public long MaxReceivedMessageSize {
get { return t.MaxReceivedMessageSize; }
set { t.MaxReceivedMessageSize = value; }
}
public override string Scheme {
- get { return Security.Mode != WebHttpSecurityMode.None ? Uri.UriSchemeHttps : Uri.UriSchemeHttp; }
+ get { return Security.Mode == WebHttpSecurityMode.Transport ? Uri.UriSchemeHttps : Uri.UriSchemeHttp; }
}
public WebHttpSecurity Security {
get { return security; }
-#if NET_4_0
set {
if (value == null)
throw new ArgumentNullException ("value");
security = value;
}
-#endif
}
public Encoding WriteEncoding {
return new BindingElementCollection (new BindingElement [] { msgenc, t.Clone () });
}
-#if !NET_2_1
bool IBindingRuntimePreferences.ReceiveSynchronously {
- get { return receive_synchronously; }
+ get { return false; }
}
-#endif
-#if NET_4_0
[EditorBrowsable (EditorBrowsableState.Advanced)]
public bool ShouldSerializeReaderQuotas ()
{
{
return false;
}
-#endif
}
}