1 // 2 // WSHttpBindingBaseElement.cs 3 // 4 // Author: 5 // Atsushi Enomoto <atsushi@ximian.com> 6 // 7 // Copyright (C) 2006 Novell, Inc. http://www.novell.com 8 // 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: 16 // 17 // The above copyright notice and this permission notice shall be 18 // included in all copies or substantial portions of the Software. 19 // 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. 27 // 28 29 using System; 30 using System.Collections; 31 using System.Collections.Generic; 32 using System.Collections.ObjectModel; 33 using System.ComponentModel; 34 using System.Configuration; 35 using System.Net; 36 using System.Net.Security; 37 using System.Reflection; 38 using System.Security.Cryptography.X509Certificates; 39 using System.Security.Principal; 40 using System.IdentityModel.Claims; 41 using System.IdentityModel.Policy; 42 using System.IdentityModel.Tokens; 43 using System.ServiceModel; 44 using System.ServiceModel.Channels; 45 using System.ServiceModel.Description; 46 using System.ServiceModel.Diagnostics; 47 using System.ServiceModel.Dispatcher; 48 using System.ServiceModel.MsmqIntegration; 49 using System.ServiceModel.PeerResolvers; 50 using System.ServiceModel.Security; 51 using System.Runtime.Serialization; 52 using System.Text; 53 using System.Xml; 54 55 namespace System.ServiceModel.Configuration 56 { 57 public abstract partial class WSHttpBindingBaseElement 58 : StandardBindingElement, IBindingConfigurationElement 59 { 60 ConfigurationPropertyCollection _properties; 61 WSHttpBindingBaseElement()62 protected WSHttpBindingBaseElement () { 63 } 64 WSHttpBindingBaseElement(string name)65 protected WSHttpBindingBaseElement (string name) 66 : base (name) { 67 } 68 69 // Properties 70 71 [ConfigurationProperty ("bypassProxyOnLocal", 72 DefaultValue = false, 73 Options = ConfigurationPropertyOptions.None)] 74 public bool BypassProxyOnLocal { 75 get { return (bool) this ["bypassProxyOnLocal"]; } 76 set { this ["bypassProxyOnLocal"] = value; } 77 } 78 79 [ConfigurationProperty ("hostNameComparisonMode", 80 DefaultValue = "StrongWildcard", 81 Options = ConfigurationPropertyOptions.None)] 82 public HostNameComparisonMode HostNameComparisonMode { 83 get { return (HostNameComparisonMode) this ["hostNameComparisonMode"]; } 84 set { this ["hostNameComparisonMode"] = value; } 85 } 86 87 [LongValidator ( MinValue = 0, 88 MaxValue = 9223372036854775807, 89 ExcludeRange = false)] 90 [ConfigurationProperty ("maxBufferPoolSize", 91 DefaultValue = "524288", 92 Options = ConfigurationPropertyOptions.None)] 93 public long MaxBufferPoolSize { 94 get { return (long) this ["maxBufferPoolSize"]; } 95 set { this ["maxBufferPoolSize"] = value; } 96 } 97 98 [LongValidator ( MinValue = 1, 99 MaxValue = 9223372036854775807, 100 ExcludeRange = false)] 101 [ConfigurationProperty ("maxReceivedMessageSize", 102 DefaultValue = "65536", 103 Options = ConfigurationPropertyOptions.None)] 104 public long MaxReceivedMessageSize { 105 get { return (long) this ["maxReceivedMessageSize"]; } 106 set { this ["maxReceivedMessageSize"] = value; } 107 } 108 109 [ConfigurationProperty ("messageEncoding", 110 DefaultValue = "Text", 111 Options = ConfigurationPropertyOptions.None)] 112 public WSMessageEncoding MessageEncoding { 113 get { return (WSMessageEncoding) this ["messageEncoding"]; } 114 set { this ["messageEncoding"] = value; } 115 } 116 117 protected override ConfigurationPropertyCollection Properties { 118 get { 119 if (_properties == null) { 120 _properties = base.Properties; 121 _properties.Add (new ConfigurationProperty ("bypassProxyOnLocal", typeof (bool), "false", new BooleanConverter (), null, ConfigurationPropertyOptions.None)); 122 _properties.Add (new ConfigurationProperty ("hostNameComparisonMode", typeof (HostNameComparisonMode), "StrongWildcard", null, null, ConfigurationPropertyOptions.None)); 123 _properties.Add (new ConfigurationProperty ("maxBufferPoolSize", typeof (long), "524288", null, new LongValidator (0, 9223372036854775807, false), ConfigurationPropertyOptions.None)); 124 _properties.Add (new ConfigurationProperty ("maxReceivedMessageSize", typeof (long), "65536", null, new LongValidator (1, 9223372036854775807, false), ConfigurationPropertyOptions.None)); 125 _properties.Add (new ConfigurationProperty ("messageEncoding", typeof (WSMessageEncoding), "Text", null, null, ConfigurationPropertyOptions.None)); 126 _properties.Add (new ConfigurationProperty ("proxyAddress", typeof (Uri), null, new UriTypeConverter (), null, ConfigurationPropertyOptions.None)); 127 _properties.Add (new ConfigurationProperty ("readerQuotas", typeof (XmlDictionaryReaderQuotasElement), null, null, null, ConfigurationPropertyOptions.None)); 128 _properties.Add (new ConfigurationProperty ("reliableSession", typeof (StandardBindingOptionalReliableSessionElement), null, null, null, ConfigurationPropertyOptions.None)); 129 _properties.Add (new ConfigurationProperty ("textEncoding", typeof (Encoding), "utf-8", EncodingConverter.Instance, null, ConfigurationPropertyOptions.None)); 130 _properties.Add (new ConfigurationProperty ("transactionFlow", typeof (bool), "false", new BooleanConverter (), null, ConfigurationPropertyOptions.None)); 131 _properties.Add (new ConfigurationProperty ("useDefaultWebProxy", typeof (bool), "true", new BooleanConverter (), null, ConfigurationPropertyOptions.None)); 132 } 133 return _properties; 134 } 135 } 136 137 [ConfigurationProperty ("proxyAddress", 138 DefaultValue = null, 139 Options = ConfigurationPropertyOptions.None)] 140 public Uri ProxyAddress { 141 get { return (Uri) this ["proxyAddress"]; } 142 set { this ["proxyAddress"] = value; } 143 } 144 145 [ConfigurationProperty ("readerQuotas", 146 Options = ConfigurationPropertyOptions.None)] 147 public XmlDictionaryReaderQuotasElement ReaderQuotas { 148 get { return (XmlDictionaryReaderQuotasElement) this ["readerQuotas"]; } 149 } 150 151 [ConfigurationProperty ("reliableSession", 152 Options = ConfigurationPropertyOptions.None)] 153 public StandardBindingOptionalReliableSessionElement ReliableSession { 154 get { return (StandardBindingOptionalReliableSessionElement) this ["reliableSession"]; } 155 } 156 157 [TypeConverter (typeof (EncodingConverter))] 158 [ConfigurationProperty ("textEncoding", 159 DefaultValue = "utf-8", 160 Options = ConfigurationPropertyOptions.None)] 161 public Encoding TextEncoding { 162 get { return (Encoding) this ["textEncoding"]; } 163 set { this ["textEncoding"] = value; } 164 } 165 166 [ConfigurationProperty ("transactionFlow", 167 DefaultValue = false, 168 Options = ConfigurationPropertyOptions.None)] 169 public bool TransactionFlow { 170 get { return (bool) this ["transactionFlow"]; } 171 set { this ["transactionFlow"] = value; } 172 } 173 174 [ConfigurationProperty ("useDefaultWebProxy", 175 DefaultValue = true, 176 Options = ConfigurationPropertyOptions.None)] 177 public bool UseDefaultWebProxy { 178 get { return (bool) this ["useDefaultWebProxy"]; } 179 set { this ["useDefaultWebProxy"] = value; } 180 } 181 OnApplyConfiguration(Binding binding)182 protected override void OnApplyConfiguration (Binding binding) 183 { 184 var b = (WSHttpBindingBase) binding; 185 b.BypassProxyOnLocal = BypassProxyOnLocal; 186 b.HostNameComparisonMode = HostNameComparisonMode; 187 b.MaxBufferPoolSize = MaxBufferPoolSize; 188 b.MaxReceivedMessageSize = MaxReceivedMessageSize; 189 b.MessageEncoding = MessageEncoding; 190 b.ProxyAddress = ProxyAddress; 191 b.ReaderQuotas = ReaderQuotas.Create (); 192 ReliableSession.ApplyConfiguration (b.ReliableSession); 193 b.TextEncoding = TextEncoding; 194 b.TransactionFlow = TransactionFlow; 195 b.UseDefaultWebProxy = UseDefaultWebProxy; 196 } 197 } 198 199 } 200