BasicHttpBindingElement.cs 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. //
  2. // BasicHttpBindingElement.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  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. using System;
  29. using System.Collections;
  30. using System.Collections.Generic;
  31. using System.Collections.ObjectModel;
  32. using System.ComponentModel;
  33. using System.Configuration;
  34. using System.Net;
  35. using System.Net.Security;
  36. using System.Reflection;
  37. using System.Security.Cryptography.X509Certificates;
  38. using System.Security.Principal;
  39. using System.IdentityModel.Claims;
  40. using System.IdentityModel.Policy;
  41. using System.IdentityModel.Tokens;
  42. using System.ServiceModel;
  43. using System.ServiceModel.Channels;
  44. using System.ServiceModel.Description;
  45. using System.ServiceModel.Diagnostics;
  46. using System.ServiceModel.Dispatcher;
  47. using System.ServiceModel.MsmqIntegration;
  48. using System.ServiceModel.PeerResolvers;
  49. using System.ServiceModel.Security;
  50. using System.Runtime.Serialization;
  51. using System.Text;
  52. using System.Xml;
  53. namespace System.ServiceModel.Configuration
  54. {
  55. public class BasicHttpBindingElement
  56. : StandardBindingElement, IBindingConfigurationElement
  57. {
  58. ConfigurationPropertyCollection _properties;
  59. public BasicHttpBindingElement ()
  60. {
  61. }
  62. public BasicHttpBindingElement (string name) : base (name) { }
  63. // Properties
  64. [ConfigurationProperty ("allowCookies",
  65. DefaultValue = false,
  66. Options = ConfigurationPropertyOptions.None)]
  67. public bool AllowCookies {
  68. get { return (bool) this ["allowCookies"]; }
  69. set { this ["allowCookies"] = value; }
  70. }
  71. protected override Type BindingElementType {
  72. get { return typeof (BasicHttpBinding); }
  73. }
  74. [ConfigurationProperty ("bypassProxyOnLocal",
  75. DefaultValue = false,
  76. Options = ConfigurationPropertyOptions.None)]
  77. public bool BypassProxyOnLocal {
  78. get { return (bool) this ["bypassProxyOnLocal"]; }
  79. set { this ["bypassProxyOnLocal"] = value; }
  80. }
  81. [ConfigurationProperty ("hostNameComparisonMode",
  82. DefaultValue = "StrongWildcard",
  83. Options = ConfigurationPropertyOptions.None)]
  84. public HostNameComparisonMode HostNameComparisonMode {
  85. get { return (HostNameComparisonMode) this ["hostNameComparisonMode"]; }
  86. set { this ["hostNameComparisonMode"] = value; }
  87. }
  88. [LongValidator ( MinValue = 0,
  89. MaxValue = 9223372036854775807,
  90. ExcludeRange = false)]
  91. [ConfigurationProperty ("maxBufferPoolSize",
  92. DefaultValue = "524288",
  93. Options = ConfigurationPropertyOptions.None)]
  94. public long MaxBufferPoolSize {
  95. get { return (long) this ["maxBufferPoolSize"]; }
  96. set { this ["maxBufferPoolSize"] = value; }
  97. }
  98. [IntegerValidator ( MinValue = 1,
  99. MaxValue = int.MaxValue,
  100. ExcludeRange = false)]
  101. [ConfigurationProperty ("maxBufferSize",
  102. DefaultValue = "65536",
  103. Options = ConfigurationPropertyOptions.None)]
  104. public int MaxBufferSize {
  105. get { return (int) this ["maxBufferSize"]; }
  106. set { this ["maxBufferSize"] = value; }
  107. }
  108. [LongValidator ( MinValue = 1,
  109. MaxValue = 9223372036854775807,
  110. ExcludeRange = false)]
  111. [ConfigurationProperty ("maxReceivedMessageSize",
  112. DefaultValue = "65536",
  113. Options = ConfigurationPropertyOptions.None)]
  114. public long MaxReceivedMessageSize {
  115. get { return (long) this ["maxReceivedMessageSize"]; }
  116. set { this ["maxReceivedMessageSize"] = value; }
  117. }
  118. [ConfigurationProperty ("messageEncoding",
  119. DefaultValue = "Text",
  120. Options = ConfigurationPropertyOptions.None)]
  121. public WSMessageEncoding MessageEncoding {
  122. get { return (WSMessageEncoding) this ["messageEncoding"]; }
  123. set { this ["messageEncoding"] = value; }
  124. }
  125. protected override ConfigurationPropertyCollection Properties {
  126. get {
  127. if (_properties == null) {
  128. _properties = base.Properties;
  129. _properties.Add (new ConfigurationProperty ("allowCookies", typeof (bool), "false", null, null, ConfigurationPropertyOptions.None));
  130. _properties.Add (new ConfigurationProperty ("bypassProxyOnLocal", typeof (bool), "false", null, null, ConfigurationPropertyOptions.None));
  131. _properties.Add (new ConfigurationProperty ("hostNameComparisonMode", typeof (HostNameComparisonMode), "StrongWildcard", null, null, ConfigurationPropertyOptions.None));
  132. _properties.Add (new ConfigurationProperty ("maxBufferPoolSize", typeof (long), "524288", null, new LongValidator (0, 9223372036854775807, false), ConfigurationPropertyOptions.None));
  133. _properties.Add (new ConfigurationProperty ("maxBufferSize", typeof (int), "65536", null, new IntegerValidator (1, int.MaxValue, false), ConfigurationPropertyOptions.None));
  134. _properties.Add (new ConfigurationProperty ("maxReceivedMessageSize", typeof (long), "65536", null, new LongValidator (1, 9223372036854775807, false), ConfigurationPropertyOptions.None));
  135. _properties.Add (new ConfigurationProperty ("messageEncoding", typeof (WSMessageEncoding), "Text", null, null, ConfigurationPropertyOptions.None));
  136. _properties.Add (new ConfigurationProperty ("proxyAddress", typeof (Uri), null, new UriTypeConverter (), null, ConfigurationPropertyOptions.None));
  137. _properties.Add (new ConfigurationProperty ("readerQuotas", typeof (XmlDictionaryReaderQuotasElement), null, null, null, ConfigurationPropertyOptions.None));
  138. _properties.Add (new ConfigurationProperty ("security", typeof (BasicHttpSecurityElement), null, null, null, ConfigurationPropertyOptions.None));
  139. _properties.Add (new ConfigurationProperty ("textEncoding", typeof (Encoding), "utf-8", EncodingConverter.Instance, null, ConfigurationPropertyOptions.None));
  140. _properties.Add (new ConfigurationProperty ("transferMode", typeof (TransferMode), "Buffered", null, null, ConfigurationPropertyOptions.None));
  141. _properties.Add (new ConfigurationProperty ("useDefaultWebProxy", typeof (bool), "true", new BooleanConverter (), null, ConfigurationPropertyOptions.None));
  142. }
  143. return _properties;
  144. }
  145. }
  146. [ConfigurationProperty ("proxyAddress",
  147. DefaultValue = null,
  148. Options = ConfigurationPropertyOptions.None)]
  149. public Uri ProxyAddress {
  150. get { return (Uri) this ["proxyAddress"]; }
  151. set { this ["proxyAddress"] = value; }
  152. }
  153. [ConfigurationProperty ("readerQuotas",
  154. Options = ConfigurationPropertyOptions.None)]
  155. public XmlDictionaryReaderQuotasElement ReaderQuotas {
  156. get { return (XmlDictionaryReaderQuotasElement) this ["readerQuotas"]; }
  157. }
  158. [ConfigurationProperty ("security",
  159. Options = ConfigurationPropertyOptions.None)]
  160. public BasicHttpSecurityElement Security {
  161. get { return (BasicHttpSecurityElement) this ["security"]; }
  162. }
  163. [TypeConverter (typeof (EncodingConverter))]
  164. [ConfigurationProperty ("textEncoding",
  165. DefaultValue = "utf-8",
  166. Options = ConfigurationPropertyOptions.None)]
  167. public Encoding TextEncoding {
  168. get { return (Encoding) this ["textEncoding"]; }
  169. set { this ["textEncoding"] = value; }
  170. }
  171. [ConfigurationProperty ("transferMode",
  172. DefaultValue = "Buffered",
  173. Options = ConfigurationPropertyOptions.None)]
  174. public TransferMode TransferMode {
  175. get { return (TransferMode) this ["transferMode"]; }
  176. set { this ["transferMode"] = value; }
  177. }
  178. [ConfigurationProperty ("useDefaultWebProxy",
  179. DefaultValue = true,
  180. Options = ConfigurationPropertyOptions.None)]
  181. public bool UseDefaultWebProxy {
  182. get { return (bool) this ["useDefaultWebProxy"]; }
  183. set { this ["useDefaultWebProxy"] = value; }
  184. }
  185. protected override void OnApplyConfiguration (Binding binding) {
  186. BasicHttpBinding basicHttpBinding = (BasicHttpBinding) binding;
  187. basicHttpBinding.AllowCookies = AllowCookies;
  188. basicHttpBinding.BypassProxyOnLocal = BypassProxyOnLocal;
  189. basicHttpBinding.HostNameComparisonMode = HostNameComparisonMode;
  190. basicHttpBinding.MaxBufferPoolSize = MaxBufferPoolSize;
  191. basicHttpBinding.MaxBufferSize = MaxBufferSize;
  192. basicHttpBinding.MaxReceivedMessageSize = MaxReceivedMessageSize;
  193. basicHttpBinding.MessageEncoding = MessageEncoding;
  194. basicHttpBinding.ProxyAddress = ProxyAddress;
  195. basicHttpBinding.ReaderQuotas.MaxArrayLength = ReaderQuotas.MaxArrayLength;
  196. basicHttpBinding.ReaderQuotas.MaxBytesPerRead = ReaderQuotas.MaxBytesPerRead;
  197. basicHttpBinding.ReaderQuotas.MaxDepth = ReaderQuotas.MaxDepth;
  198. basicHttpBinding.ReaderQuotas.MaxNameTableCharCount = ReaderQuotas.MaxNameTableCharCount;
  199. basicHttpBinding.ReaderQuotas.MaxStringContentLength = ReaderQuotas.MaxStringContentLength;
  200. basicHttpBinding.Security.Mode = Security.Mode;
  201. basicHttpBinding.TextEncoding = TextEncoding;
  202. basicHttpBinding.TransferMode = TransferMode;
  203. basicHttpBinding.UseDefaultWebProxy = UseDefaultWebProxy;
  204. }
  205. }
  206. }