| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using System.ComponentModel; |
| | | 6 | | using System.Configuration; |
| | | 7 | | using System.Text; |
| | | 8 | | using CoreWCF.Channels; |
| | | 9 | | |
| | | 10 | | namespace CoreWCF.Configuration |
| | | 11 | | { |
| | | 12 | | public class WebHttpBindingElement : StandardBindingElement |
| | | 13 | | { |
| | 0 | 14 | | private static readonly Type WebContentTypeMapperType = typeof(WebContentTypeMapper); |
| | | 15 | | |
| | | 16 | | public WebHttpBindingElement(string name) |
| | 3 | 17 | | : base(name) |
| | | 18 | | { |
| | 3 | 19 | | } |
| | | 20 | | |
| | | 21 | | public WebHttpBindingElement() |
| | 3 | 22 | | : this(null) |
| | | 23 | | { |
| | 3 | 24 | | } |
| | | 25 | | |
| | | 26 | | [ConfigurationProperty(ConfigurationStrings.AllowCookies, DefaultValue = HttpTransportDefaults.AllowCookies)] |
| | | 27 | | public bool AllowCookies |
| | | 28 | | { |
| | 0 | 29 | | get { return (bool)base[ConfigurationStrings.AllowCookies]; } |
| | 0 | 30 | | set { base[ConfigurationStrings.AllowCookies] = value; } |
| | | 31 | | |
| | | 32 | | } |
| | | 33 | | |
| | | 34 | | [ConfigurationProperty(ConfigurationStrings.BypassProxyOnLocal, DefaultValue = HttpTransportDefaults.BypassProxy |
| | | 35 | | public bool BypassProxyOnLocal |
| | | 36 | | { |
| | 0 | 37 | | get { return (bool)base[ConfigurationStrings.BypassProxyOnLocal]; } |
| | 0 | 38 | | set { base[ConfigurationStrings.BypassProxyOnLocal] = value; } |
| | | 39 | | } |
| | | 40 | | |
| | | 41 | | [ConfigurationProperty(ConfigurationStrings.HostNameComparisonMode, DefaultValue = HttpTransportDefaults.HostNam |
| | | 42 | | public HostNameComparisonMode HostNameComparisonMode |
| | | 43 | | { |
| | 0 | 44 | | get { return (HostNameComparisonMode)base[ConfigurationStrings.HostNameComparisonMode]; } |
| | 0 | 45 | | set { base[ConfigurationStrings.HostNameComparisonMode] = value; } |
| | | 46 | | } |
| | | 47 | | |
| | | 48 | | [ConfigurationProperty(ConfigurationStrings.MaxBufferPoolSize, DefaultValue = TransportDefaults.MaxBufferPoolSiz |
| | | 49 | | [LongValidator(MinValue = 0)] |
| | | 50 | | public long MaxBufferPoolSize |
| | | 51 | | { |
| | 2 | 52 | | get { return (long)base[ConfigurationStrings.MaxBufferPoolSize]; } |
| | 0 | 53 | | set { base[ConfigurationStrings.MaxBufferPoolSize] = value; } |
| | | 54 | | } |
| | | 55 | | |
| | | 56 | | [ConfigurationProperty(ConfigurationStrings.MaxBufferSize, DefaultValue = TransportDefaults.MaxBufferSize)] |
| | | 57 | | [IntegerValidator(MinValue = 1)] |
| | | 58 | | public int MaxBufferSize |
| | | 59 | | { |
| | 3 | 60 | | get { return (int)base[ConfigurationStrings.MaxBufferSize]; } |
| | 0 | 61 | | set { base[ConfigurationStrings.MaxBufferSize] = value; } |
| | | 62 | | } |
| | | 63 | | |
| | | 64 | | [ConfigurationProperty(ConfigurationStrings.MaxReceivedMessageSize, DefaultValue = TransportDefaults.MaxReceived |
| | | 65 | | [LongValidator(MinValue = 1)] |
| | | 66 | | public long MaxReceivedMessageSize |
| | | 67 | | { |
| | 3 | 68 | | get { return (long)base[ConfigurationStrings.MaxReceivedMessageSize]; } |
| | 0 | 69 | | set { base[ConfigurationStrings.MaxReceivedMessageSize] = value; } |
| | | 70 | | } |
| | | 71 | | |
| | | 72 | | [ConfigurationProperty(ConfigurationStrings.ProxyAddress, DefaultValue = HttpTransportDefaults.ProxyAddress)] |
| | | 73 | | public Uri ProxyAddress |
| | | 74 | | { |
| | 0 | 75 | | get { return (Uri)base[ConfigurationStrings.ProxyAddress]; } |
| | 0 | 76 | | set { base[ConfigurationStrings.ProxyAddress] = value; } |
| | | 77 | | } |
| | | 78 | | |
| | | 79 | | [ConfigurationProperty(ConfigurationStrings.ReaderQuotas)] |
| | | 80 | | public XmlDictionaryReaderQuotasElement ReaderQuotas |
| | | 81 | | { |
| | 3 | 82 | | get { return (XmlDictionaryReaderQuotasElement)base[ConfigurationStrings.ReaderQuotas]; } |
| | | 83 | | } |
| | | 84 | | |
| | | 85 | | [ConfigurationProperty(ConfigurationStrings.Security)] |
| | | 86 | | public WebHttpSecurityElement Security |
| | | 87 | | { |
| | 3 | 88 | | get { return (WebHttpSecurityElement)base[ConfigurationStrings.Security]; } |
| | | 89 | | } |
| | | 90 | | |
| | | 91 | | [ConfigurationProperty(ConfigurationStrings.TransferMode, DefaultValue = HttpTransportDefaults.TransferMode)] |
| | | 92 | | public TransferMode TransferMode |
| | | 93 | | { |
| | 2 | 94 | | get { return (TransferMode)base[ConfigurationStrings.TransferMode]; } |
| | 0 | 95 | | set { base[ConfigurationStrings.TransferMode] = value; } |
| | | 96 | | } |
| | | 97 | | |
| | | 98 | | [ConfigurationProperty(ConfigurationStrings.UseDefaultWebProxy, DefaultValue = HttpTransportDefaults.UseDefaultW |
| | | 99 | | public bool UseDefaultWebProxy |
| | | 100 | | { |
| | 0 | 101 | | get { return (bool)base[ConfigurationStrings.UseDefaultWebProxy]; } |
| | 0 | 102 | | set { base[ConfigurationStrings.UseDefaultWebProxy] = value; } |
| | | 103 | | } |
| | | 104 | | |
| | | 105 | | [ConfigurationProperty(ConfigurationStrings.WriteEncoding, DefaultValue = TextEncoderDefaults.EncodingString)] |
| | | 106 | | [TypeConverter(typeof(EncodingConverter))] |
| | | 107 | | public Encoding WriteEncoding |
| | | 108 | | { |
| | 2 | 109 | | get { return (Encoding)base[ConfigurationStrings.WriteEncoding]; } |
| | 0 | 110 | | set { base[ConfigurationStrings.WriteEncoding] = value; } |
| | | 111 | | } |
| | | 112 | | |
| | | 113 | | [ConfigurationProperty(ConfigurationStrings.ContentTypeMapper, DefaultValue = "")] |
| | | 114 | | [StringValidator(MinLength = 0)] |
| | | 115 | | public string ContentTypeMapper |
| | | 116 | | { |
| | 2 | 117 | | get { return (string)base[ConfigurationStrings.ContentTypeMapper]; } |
| | | 118 | | set |
| | | 119 | | { |
| | 0 | 120 | | if (String.IsNullOrEmpty(value)) |
| | | 121 | | { |
| | 0 | 122 | | value = String.Empty; |
| | | 123 | | } |
| | 0 | 124 | | base[ConfigurationStrings.ContentTypeMapper] = value; |
| | 0 | 125 | | } |
| | | 126 | | } |
| | | 127 | | |
| | | 128 | | [ConfigurationProperty(ConfigurationStrings.CrossDomainScriptAccessEnabled, DefaultValue = false)] |
| | | 129 | | public bool CrossDomainScriptAccessEnabled |
| | | 130 | | { |
| | 0 | 131 | | get { return (bool)base[ConfigurationStrings.CrossDomainScriptAccessEnabled]; } |
| | 0 | 132 | | set { base[ConfigurationStrings.CrossDomainScriptAccessEnabled] = value; } |
| | | 133 | | } |
| | | 134 | | |
| | | 135 | | public override Binding CreateBinding() |
| | | 136 | | { |
| | 2 | 137 | | var binding = new WebHttpBinding(WebHttpSecurityMode.None) |
| | 2 | 138 | | { |
| | 2 | 139 | | Name = Name, |
| | 2 | 140 | | MaxBufferPoolSize = MaxBufferPoolSize, |
| | 2 | 141 | | MaxBufferSize = MaxBufferSize, |
| | 2 | 142 | | MaxReceivedMessageSize = MaxReceivedMessageSize, |
| | 2 | 143 | | TransferMode = TransferMode, |
| | 2 | 144 | | // commented due to null reference exception |
| | 2 | 145 | | //CrossDomainScriptAccessEnabled = CrossDomainScriptAccessEnabled, |
| | 2 | 146 | | ContentTypeMapper = GetContentTypeMapper(this.ContentTypeMapper), |
| | 2 | 147 | | ReaderQuotas = ReaderQuotas.Clone(), |
| | 2 | 148 | | ReceiveTimeout = ReceiveTimeout, |
| | 2 | 149 | | OpenTimeout = OpenTimeout, |
| | 2 | 150 | | CloseTimeout = CloseTimeout, |
| | 2 | 151 | | SendTimeout = SendTimeout, |
| | 2 | 152 | | WriteEncoding = WriteEncoding, |
| | 2 | 153 | | }; |
| | | 154 | | |
| | 2 | 155 | | Security.ApplyConfiguration(binding.Security); |
| | 2 | 156 | | return binding; |
| | | 157 | | } |
| | | 158 | | |
| | | 159 | | internal static WebContentTypeMapper GetContentTypeMapper(string contentTypeMapperType) |
| | | 160 | | { |
| | 2 | 161 | | WebContentTypeMapper contentTypeMapper = null; |
| | 2 | 162 | | if (!string.IsNullOrEmpty(contentTypeMapperType)) |
| | | 163 | | { |
| | 0 | 164 | | Type type = System.Type.GetType(contentTypeMapperType, true); |
| | 0 | 165 | | if (!WebContentTypeMapperType.IsAssignableFrom(type)) |
| | | 166 | | { |
| | 0 | 167 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.Config |
| | | 168 | | } |
| | 0 | 169 | | contentTypeMapper = (WebContentTypeMapper)Activator.CreateInstance(type); |
| | | 170 | | } |
| | 2 | 171 | | return contentTypeMapper; |
| | | 172 | | } |
| | | 173 | | } |
| | | 174 | | } |