| | | 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.Net; |
| | | 8 | | using CoreWCF.Channels; |
| | | 9 | | |
| | | 10 | | namespace CoreWCF.Configuration |
| | | 11 | | { |
| | | 12 | | public class HttpTransportElement : TransportElement |
| | | 13 | | { |
| | | 14 | | //[ConfigurationProperty(ConfigurationStrings.AllowCookies, DefaultValue = HttpTransportDefaults.AllowCookies)] |
| | | 15 | | //public bool AllowCookies |
| | | 16 | | //{ |
| | | 17 | | // get { return (bool)base[ConfigurationStrings.AllowCookies]; } |
| | | 18 | | // set { base[ConfigurationStrings.AllowCookies] = value; } |
| | | 19 | | //} |
| | | 20 | | |
| | | 21 | | //[ConfigurationProperty(ConfigurationStrings.RequestInitializationTimeout, DefaultValue = HttpTransportDefaults |
| | | 22 | | //public TimeSpan RequestInitializationTimeout |
| | | 23 | | //{ |
| | | 24 | | // get { return (TimeSpan)base[ConfigurationStrings.RequestInitializationTimeout]; } |
| | | 25 | | // set { base[ConfigurationStrings.RequestInitializationTimeout] = value; } |
| | | 26 | | //} |
| | | 27 | | |
| | | 28 | | [ConfigurationProperty(ConfigurationStrings.AuthenticationScheme, DefaultValue = HttpTransportDefaults.Authentic |
| | | 29 | | public AuthenticationSchemes AuthenticationScheme |
| | | 30 | | { |
| | 4 | 31 | | get { return (AuthenticationSchemes)base[ConfigurationStrings.AuthenticationScheme]; } |
| | 0 | 32 | | set { base[ConfigurationStrings.AuthenticationScheme] = value; } |
| | | 33 | | } |
| | | 34 | | |
| | | 35 | | public override Type BindingElementType |
| | | 36 | | { |
| | 12 | 37 | | get { return typeof(HttpTransportBindingElement); } |
| | | 38 | | } |
| | | 39 | | |
| | | 40 | | //[ConfigurationProperty(ConfigurationStrings.BypassProxyOnLocal, DefaultValue = HttpTransportDefaults.BypassPro |
| | | 41 | | //public bool BypassProxyOnLocal |
| | | 42 | | //{ |
| | | 43 | | // get { return (bool)base[ConfigurationStrings.BypassProxyOnLocal]; } |
| | | 44 | | // set { base[ConfigurationStrings.BypassProxyOnLocal] = value; } |
| | | 45 | | //} |
| | | 46 | | |
| | | 47 | | //[ConfigurationProperty(ConfigurationStrings.DecompressionEnabled, DefaultValue = HttpTransportDefaults.Decompr |
| | | 48 | | //public bool DecompressionEnabled |
| | | 49 | | //{ |
| | | 50 | | // get { return (bool)base[ConfigurationStrings.DecompressionEnabled]; } |
| | | 51 | | // set { base[ConfigurationStrings.DecompressionEnabled] = value; } |
| | | 52 | | //} |
| | | 53 | | |
| | | 54 | | //[ConfigurationProperty(ConfigurationStrings.HostNameComparisonMode, DefaultValue = HttpTransportDefaults.HostN |
| | | 55 | | //public HostNameComparisonMode HostNameComparisonMode |
| | | 56 | | //{ |
| | | 57 | | // get { return (HostNameComparisonMode)base[ConfigurationStrings.HostNameComparisonMode]; } |
| | | 58 | | // set { base[ConfigurationStrings.HostNameComparisonMode] = value; } |
| | | 59 | | //} |
| | | 60 | | |
| | | 61 | | [ConfigurationProperty(ConfigurationStrings.KeepAliveEnabled, DefaultValue = HttpTransportDefaults.KeepAliveEnab |
| | | 62 | | public bool KeepAliveEnabled |
| | | 63 | | { |
| | 4 | 64 | | get { return (bool)base[ConfigurationStrings.KeepAliveEnabled]; } |
| | 0 | 65 | | set { base[ConfigurationStrings.KeepAliveEnabled] = value; } |
| | | 66 | | } |
| | | 67 | | |
| | | 68 | | [ConfigurationProperty(ConfigurationStrings.MaxBufferSize, DefaultValue = TransportDefaults.MaxBufferSize)] |
| | | 69 | | [IntegerValidator(MinValue = 1)] |
| | | 70 | | public int MaxBufferSize |
| | | 71 | | { |
| | 2 | 72 | | get { return (int)base[ConfigurationStrings.MaxBufferSize]; } |
| | 0 | 73 | | set { base[ConfigurationStrings.MaxBufferSize] = value; } |
| | | 74 | | } |
| | | 75 | | |
| | | 76 | | //[ConfigurationProperty(ConfigurationStrings.MaxPendingAccepts, DefaultValue = HttpTransportDefaults.DefaultMax |
| | | 77 | | //public int MaxPendingAccepts |
| | | 78 | | //{ |
| | | 79 | | // get { return (int)base[ConfigurationStrings.MaxPendingAccepts]; } |
| | | 80 | | // set { base[ConfigurationStrings.MaxPendingAccepts] = value; } |
| | | 81 | | //} |
| | | 82 | | |
| | | 83 | | //[ConfigurationProperty(ConfigurationStrings.MessageHandlerFactory, DefaultValue = HttpTransportDefaults.Messag |
| | | 84 | | //public HttpMessageHandlerFactoryElement MessageHandlerFactory |
| | | 85 | | //{ |
| | | 86 | | // get { return (HttpMessageHandlerFactoryElement)this[ConfigurationStrings.MessageHandlerFactory]; } |
| | | 87 | | // set { base[ConfigurationStrings.MessageHandlerFactory] = value; } |
| | | 88 | | //} |
| | | 89 | | |
| | | 90 | | //[ConfigurationProperty(ConfigurationStrings.ProxyAddress, DefaultValue = HttpTransportDefaults.ProxyAddress)] |
| | | 91 | | //public Uri ProxyAddress |
| | | 92 | | //{ |
| | | 93 | | // get { return (Uri)base[ConfigurationStrings.ProxyAddress]; } |
| | | 94 | | // set { base[ConfigurationStrings.ProxyAddress] = value; } |
| | | 95 | | //} |
| | | 96 | | |
| | | 97 | | //[ConfigurationProperty(ConfigurationStrings.ProxyAuthenticationScheme, DefaultValue = HttpTransportDefaults.Pr |
| | | 98 | | //public AuthenticationSchemes ProxyAuthenticationScheme |
| | | 99 | | //{ |
| | | 100 | | // get { return (AuthenticationSchemes)base[ConfigurationStrings.ProxyAuthenticationScheme]; } |
| | | 101 | | // set { base[ConfigurationStrings.ProxyAuthenticationScheme] = value; } |
| | | 102 | | //} |
| | | 103 | | |
| | | 104 | | [ConfigurationProperty(ConfigurationStrings.Realm, DefaultValue = HttpTransportDefaults.Realm)] |
| | | 105 | | [StringValidator(MinLength = 0)] |
| | | 106 | | public string Realm |
| | | 107 | | { |
| | 4 | 108 | | get { return (string)base[ConfigurationStrings.Realm]; } |
| | | 109 | | set |
| | | 110 | | { |
| | 0 | 111 | | if (string.IsNullOrEmpty(value)) |
| | | 112 | | { |
| | 0 | 113 | | value = string.Empty; |
| | | 114 | | } |
| | 0 | 115 | | base[ConfigurationStrings.Realm] = value; |
| | 0 | 116 | | } |
| | | 117 | | } |
| | | 118 | | |
| | | 119 | | [ConfigurationProperty(ConfigurationStrings.TransferMode, DefaultValue = HttpTransportDefaults.TransferMode)] |
| | | 120 | | public TransferMode TransferMode |
| | | 121 | | { |
| | 4 | 122 | | get { return (TransferMode)base[ConfigurationStrings.TransferMode]; } |
| | 0 | 123 | | set { base[ConfigurationStrings.TransferMode] = value; } |
| | | 124 | | } |
| | | 125 | | |
| | | 126 | | //[ConfigurationProperty(ConfigurationStrings.UnsafeConnectionNtlmAuthentication, DefaultValue = HttpTransportDe |
| | | 127 | | //public bool UnsafeConnectionNtlmAuthentication |
| | | 128 | | //{ |
| | | 129 | | // get { return (bool)base[ConfigurationStrings.UnsafeConnectionNtlmAuthentication]; } |
| | | 130 | | // set { base[ConfigurationStrings.UnsafeConnectionNtlmAuthentication] = value; } |
| | | 131 | | //} |
| | | 132 | | |
| | | 133 | | //[ConfigurationProperty(ConfigurationStrings.UseDefaultWebProxy, DefaultValue = HttpTransportDefaults.UseDefaul |
| | | 134 | | //public bool UseDefaultWebProxy |
| | | 135 | | //{ |
| | | 136 | | // get { return (bool)base[ConfigurationStrings.UseDefaultWebProxy]; } |
| | | 137 | | // set { base[ConfigurationStrings.UseDefaultWebProxy] = value; } |
| | | 138 | | //} |
| | | 139 | | |
| | | 140 | | |
| | | 141 | | [ConfigurationProperty(ConfigurationStrings.ExtendedProtectionPolicy)] |
| | | 142 | | public ExtendedProtectionPolicyElement ExtendedProtectionPolicy |
| | | 143 | | { |
| | 4 | 144 | | get { return (ExtendedProtectionPolicyElement)base[ConfigurationStrings.ExtendedProtectionPolicy]; } |
| | 0 | 145 | | private set { base[ConfigurationStrings.ExtendedProtectionPolicy] = value; } |
| | | 146 | | } |
| | | 147 | | |
| | | 148 | | [ConfigurationProperty(ConfigurationStrings.WebSocketSettingsSectionName)] |
| | | 149 | | public WebSocketTransportSettingsElement WebSocketSettings |
| | | 150 | | { |
| | 4 | 151 | | get { return (WebSocketTransportSettingsElement)base[ConfigurationStrings.WebSocketSettingsSectionName]; } |
| | 0 | 152 | | set { base[ConfigurationStrings.WebSocketSettingsSectionName] = value; } |
| | | 153 | | } |
| | | 154 | | |
| | | 155 | | public override void ApplyConfiguration(BindingElement bindingElement) |
| | | 156 | | { |
| | 4 | 157 | | base.ApplyConfiguration(bindingElement); |
| | 4 | 158 | | HttpTransportBindingElement binding = (HttpTransportBindingElement)bindingElement; |
| | | 159 | | |
| | | 160 | | //binding.AllowCookies = this.AllowCookies; |
| | 4 | 161 | | binding.AuthenticationScheme = AuthenticationScheme; |
| | | 162 | | //binding.BypassProxyOnLocal = this.BypassProxyOnLocal; |
| | | 163 | | //binding.DecompressionEnabled = this.DecompressionEnabled; |
| | 4 | 164 | | binding.KeepAliveEnabled = KeepAliveEnabled; |
| | | 165 | | //binding.HostNameComparisonMode = this.HostNameComparisonMode; |
| | 4 | 166 | | PropertyInformationCollection propertyInfo = ElementInformation.Properties; |
| | 4 | 167 | | if (propertyInfo[ConfigurationStrings.MaxBufferSize].ValueOrigin != PropertyValueOrigin.Default) |
| | | 168 | | { |
| | 2 | 169 | | binding.MaxBufferSize = MaxBufferSize; |
| | | 170 | | } |
| | | 171 | | //binding.MaxPendingAccepts = this.MaxPendingAccepts; |
| | | 172 | | //binding.ProxyAddress = this.ProxyAddress; |
| | | 173 | | //binding.ProxyAuthenticationScheme = this.ProxyAuthenticationScheme; |
| | 4 | 174 | | binding.Realm = Realm; |
| | | 175 | | //binding.RequestInitializationTimeout = this.RequestInitializationTimeout; |
| | 4 | 176 | | binding.TransferMode = TransferMode; |
| | | 177 | | //binding.UnsafeConnectionNtlmAuthentication = this.UnsafeConnectionNtlmAuthentication; |
| | | 178 | | //binding.UseDefaultWebProxy = this.UseDefaultWebProxy; |
| | 4 | 179 | | binding.ExtendedProtectionPolicy = ConfigurationChannelBindingUtility.BuildPolicy(ExtendedProtectionPolicy); |
| | 4 | 180 | | WebSocketSettings.ApplyConfiguration(binding.WebSocketSettings); |
| | | 181 | | //if (this.MessageHandlerFactory != null) |
| | | 182 | | //{ |
| | | 183 | | // binding.MessageHandlerFactory = HttpMessageHandlerFactory.CreateFromConfigurationElement(this.MessageH |
| | | 184 | | //} |
| | 4 | 185 | | } |
| | | 186 | | |
| | | 187 | | public override void CopyFrom(ServiceModelExtensionElement from) |
| | | 188 | | { |
| | 0 | 189 | | base.CopyFrom(from); |
| | | 190 | | |
| | 0 | 191 | | HttpTransportElement source = (HttpTransportElement)from; |
| | | 192 | | //this.AllowCookies = source.AllowCookies; |
| | | 193 | | //this.RequestInitializationTimeout = source.RequestInitializationTimeout; |
| | 0 | 194 | | AuthenticationScheme = source.AuthenticationScheme; |
| | | 195 | | //this.BypassProxyOnLocal = source.BypassProxyOnLocal; |
| | | 196 | | //this.DecompressionEnabled = source.DecompressionEnabled; |
| | 0 | 197 | | KeepAliveEnabled = source.KeepAliveEnabled; |
| | | 198 | | //this.HostNameComparisonMode = source.HostNameComparisonMode; |
| | 0 | 199 | | MaxBufferSize = source.MaxBufferSize; |
| | | 200 | | //this.MaxPendingAccepts = source.MaxPendingAccepts; |
| | | 201 | | //this.ProxyAddress = source.ProxyAddress; |
| | | 202 | | //this.ProxyAuthenticationScheme = source.ProxyAuthenticationScheme; |
| | 0 | 203 | | Realm = source.Realm; |
| | 0 | 204 | | TransferMode = source.TransferMode; |
| | | 205 | | //this.UnsafeConnectionNtlmAuthentication = source.UnsafeConnectionNtlmAuthentication; |
| | | 206 | | //this.UseDefaultWebProxy = source.UseDefaultWebProxy; |
| | 0 | 207 | | WebSocketSettings = source.WebSocketSettings; |
| | | 208 | | //this.MessageHandlerFactory = source.MessageHandlerFactory; |
| | 0 | 209 | | ConfigurationChannelBindingUtility.CopyFrom(source.ExtendedProtectionPolicy, ExtendedProtectionPolicy); |
| | 0 | 210 | | } |
| | | 211 | | |
| | | 212 | | protected override TransportBindingElement CreateDefaultBindingElement() |
| | | 213 | | { |
| | 2 | 214 | | return new HttpTransportBindingElement(); |
| | | 215 | | } |
| | | 216 | | |
| | | 217 | | protected internal override void InitializeFrom(BindingElement bindingElement) |
| | | 218 | | { |
| | 0 | 219 | | base.InitializeFrom(bindingElement); |
| | 0 | 220 | | HttpTransportBindingElement source = (HttpTransportBindingElement)bindingElement; |
| | | 221 | | //SetPropertyValueIfNotDefaultValue(ConfigurationStrings.AllowCookies, source.AllowCookies); |
| | 0 | 222 | | SetPropertyValueIfNotDefaultValue(ConfigurationStrings.AuthenticationScheme, source.AuthenticationScheme); |
| | | 223 | | //SetPropertyValueIfNotDefaultValue(ConfigurationStrings.DecompressionEnabled, source.DecompressionEnabled); |
| | | 224 | | //SetPropertyValueIfNotDefaultValue(ConfigurationStrings.BypassProxyOnLocal, source.BypassProxyOnLocal); |
| | 0 | 225 | | SetPropertyValueIfNotDefaultValue(ConfigurationStrings.KeepAliveEnabled, source.KeepAliveEnabled); |
| | | 226 | | //SetPropertyValueIfNotDefaultValue(ConfigurationStrings.HostNameComparisonMode, source.HostNameComparisonMo |
| | 0 | 227 | | SetPropertyValueIfNotDefaultValue(ConfigurationStrings.MaxBufferSize, source.MaxBufferSize); |
| | | 228 | | //SetPropertyValueIfNotDefaultValue(ConfigurationStrings.MaxPendingAccepts, source.MaxPendingAccepts); |
| | | 229 | | //SetPropertyValueIfNotDefaultValue(ConfigurationStrings.ProxyAddress, source.ProxyAddress); |
| | | 230 | | //SetPropertyValueIfNotDefaultValue(ConfigurationStrings.ProxyAuthenticationScheme, source.ProxyAuthenticati |
| | 0 | 231 | | SetPropertyValueIfNotDefaultValue(ConfigurationStrings.Realm, source.Realm); |
| | | 232 | | //SetPropertyValueIfNotDefaultValue(ConfigurationStrings.RequestInitializationTimeout, source.RequestInitial |
| | 0 | 233 | | SetPropertyValueIfNotDefaultValue(ConfigurationStrings.TransferMode, source.TransferMode); |
| | | 234 | | //SetPropertyValueIfNotDefaultValue(ConfigurationStrings.UnsafeConnectionNtlmAuthentication, source.UnsafeCo |
| | | 235 | | //SetPropertyValueIfNotDefaultValue(ConfigurationStrings.UseDefaultWebProxy, source.UseDefaultWebProxy); |
| | 0 | 236 | | WebSocketSettings.InitializeFrom(source.WebSocketSettings); |
| | | 237 | | //if (source.MessageHandlerFactory != null) |
| | | 238 | | //{ |
| | | 239 | | // this.MessageHandlerFactory = source.MessageHandlerFactory.GenerateConfigurationElement(); |
| | | 240 | | //} |
| | | 241 | | |
| | 0 | 242 | | ConfigurationChannelBindingUtility.InitializeFrom(source.ExtendedProtectionPolicy, ExtendedProtectionPolicy) |
| | 0 | 243 | | } |
| | | 244 | | } |
| | | 245 | | } |