WebHttpBindingElement.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. //
  2. // WebHttpBindingElement.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // Copyright (C) 2008 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.ServiceModel;
  38. using System.ServiceModel.Channels;
  39. using System.ServiceModel.Description;
  40. using System.ServiceModel.Diagnostics;
  41. using System.ServiceModel.Dispatcher;
  42. using System.Runtime.Serialization;
  43. using System.Text;
  44. using System.Xml;
  45. namespace System.ServiceModel.Configuration
  46. {
  47. [MonoTODO]
  48. public partial class WebHttpBindingElement
  49. : StandardBindingElement, IBindingConfigurationElement
  50. {
  51. // Static Fields
  52. static bool base_merged;
  53. static ConfigurationPropertyCollection properties;
  54. static ConfigurationProperty allow_cookies;
  55. static ConfigurationProperty bypass_proxy_on_local;
  56. static ConfigurationProperty host_name_comparison_mode;
  57. static ConfigurationProperty max_buffer_pool_size;
  58. static ConfigurationProperty max_buffer_size;
  59. static ConfigurationProperty max_received_message_size;
  60. static ConfigurationProperty proxy_address;
  61. static ConfigurationProperty reader_quotas;
  62. static ConfigurationProperty security;
  63. static ConfigurationProperty write_encoding;
  64. static ConfigurationProperty transfer_mode;
  65. static ConfigurationProperty use_default_web_proxy;
  66. static WebHttpBindingElement ()
  67. {
  68. properties = new ConfigurationPropertyCollection ();
  69. allow_cookies = new ConfigurationProperty ("allowCookies",
  70. typeof (bool), "false", new BooleanConverter (), null,
  71. ConfigurationPropertyOptions.None);
  72. bypass_proxy_on_local = new ConfigurationProperty ("bypassProxyOnLocal",
  73. typeof (bool), "false", new BooleanConverter (), null,
  74. ConfigurationPropertyOptions.None);
  75. host_name_comparison_mode = new ConfigurationProperty ("hostNameComparisonMode",
  76. typeof (HostNameComparisonMode), "StrongWildcard", null/* FIXME: get converter for HostNameComparisonMode*/, null,
  77. ConfigurationPropertyOptions.None);
  78. max_buffer_pool_size = new ConfigurationProperty ("maxBufferPoolSize",
  79. typeof (long), "524288", new Int64Converter (), null,
  80. ConfigurationPropertyOptions.None);
  81. max_buffer_size = new ConfigurationProperty ("maxBufferSize",
  82. typeof (int), "65536", new Int32Converter (), null,
  83. ConfigurationPropertyOptions.None);
  84. max_received_message_size = new ConfigurationProperty ("maxReceivedMessageSize",
  85. typeof (long), "65536", new Int64Converter (), null,
  86. ConfigurationPropertyOptions.None);
  87. proxy_address = new ConfigurationProperty ("proxyAddress",
  88. typeof (Uri), null, new UriTypeConverter (), null,
  89. ConfigurationPropertyOptions.None);
  90. reader_quotas = new ConfigurationProperty ("readerQuotas",
  91. typeof (XmlDictionaryReaderQuotasElement), null, null/* FIXME: get converter for XmlDictionaryReaderQuotasElement*/, null,
  92. ConfigurationPropertyOptions.None);
  93. security = new ConfigurationProperty ("security",
  94. typeof (WebHttpSecurityElement), null, null/* FIXME: get converter for WebHttpSecurityElement*/, null,
  95. ConfigurationPropertyOptions.None);
  96. write_encoding = new ConfigurationProperty ("writeEncoding",
  97. typeof (Encoding), "utf-8", new EncodingConverter (), null,
  98. ConfigurationPropertyOptions.None);
  99. transfer_mode = new ConfigurationProperty ("transferMode",
  100. typeof (TransferMode), "Buffered", null/* FIXME: get converter for TransferMode*/, null,
  101. ConfigurationPropertyOptions.None);
  102. use_default_web_proxy = new ConfigurationProperty ("useDefaultWebProxy",
  103. typeof (bool), "true", new BooleanConverter (), null,
  104. ConfigurationPropertyOptions.None);
  105. properties.Add (allow_cookies);
  106. properties.Add (bypass_proxy_on_local);
  107. properties.Add (host_name_comparison_mode);
  108. properties.Add (max_buffer_pool_size);
  109. properties.Add (max_buffer_size);
  110. properties.Add (max_received_message_size);
  111. properties.Add (proxy_address);
  112. properties.Add (reader_quotas);
  113. properties.Add (security);
  114. properties.Add (write_encoding);
  115. properties.Add (transfer_mode);
  116. properties.Add (use_default_web_proxy);
  117. }
  118. public WebHttpBindingElement ()
  119. {
  120. }
  121. // Properties
  122. [ConfigurationProperty ("allowCookies",
  123. DefaultValue = false,
  124. Options = ConfigurationPropertyOptions.None)]
  125. public bool AllowCookies {
  126. get { return (bool) base [allow_cookies]; }
  127. set { base [allow_cookies] = value; }
  128. }
  129. protected override Type BindingElementType {
  130. get { return typeof (WebHttpBinding); }
  131. }
  132. [ConfigurationProperty ("bypassProxyOnLocal",
  133. DefaultValue = false,
  134. Options = ConfigurationPropertyOptions.None)]
  135. public bool BypassProxyOnLocal {
  136. get { return (bool) base [bypass_proxy_on_local]; }
  137. set { base [bypass_proxy_on_local] = value; }
  138. }
  139. [ConfigurationProperty ("hostNameComparisonMode",
  140. DefaultValue = "StrongWildcard",
  141. Options = ConfigurationPropertyOptions.None)]
  142. public HostNameComparisonMode HostNameComparisonMode {
  143. get { return (HostNameComparisonMode) base [host_name_comparison_mode]; }
  144. set { base [host_name_comparison_mode] = value; }
  145. }
  146. [LongValidator ( MinValue = 0,
  147. MaxValue = 9223372036854775807,
  148. ExcludeRange = false)]
  149. [ConfigurationProperty ("maxBufferPoolSize",
  150. DefaultValue = "524288",
  151. Options = ConfigurationPropertyOptions.None)]
  152. public long MaxBufferPoolSize {
  153. get { return (long) base [max_buffer_pool_size]; }
  154. set { base [max_buffer_pool_size] = value; }
  155. }
  156. [IntegerValidator ( MinValue = 1,
  157. MaxValue = int.MaxValue,
  158. ExcludeRange = false)]
  159. [ConfigurationProperty ("maxBufferSize",
  160. DefaultValue = "65536",
  161. Options = ConfigurationPropertyOptions.None)]
  162. public int MaxBufferSize {
  163. get { return (int) base [max_buffer_size]; }
  164. set { base [max_buffer_size] = value; }
  165. }
  166. [LongValidator ( MinValue = 1,
  167. MaxValue = 9223372036854775807,
  168. ExcludeRange = false)]
  169. [ConfigurationProperty ("maxReceivedMessageSize",
  170. DefaultValue = "65536",
  171. Options = ConfigurationPropertyOptions.None)]
  172. public long MaxReceivedMessageSize {
  173. get { return (long) base [max_received_message_size]; }
  174. set { base [max_received_message_size] = value; }
  175. }
  176. protected override ConfigurationPropertyCollection Properties {
  177. get {
  178. if (!base_merged) {
  179. lock (properties) {
  180. base_merged = true;
  181. foreach (ConfigurationProperty p in base.Properties)
  182. properties.Add (p);
  183. }
  184. }
  185. return properties;
  186. }
  187. }
  188. [ConfigurationProperty ("proxyAddress",
  189. DefaultValue = null,
  190. Options = ConfigurationPropertyOptions.None)]
  191. public Uri ProxyAddress {
  192. get { return (Uri) base [proxy_address]; }
  193. set { base [proxy_address] = value; }
  194. }
  195. [ConfigurationProperty ("readerQuotas",
  196. Options = ConfigurationPropertyOptions.None)]
  197. public XmlDictionaryReaderQuotasElement ReaderQuotas {
  198. get { return (XmlDictionaryReaderQuotasElement) base [reader_quotas]; }
  199. }
  200. [ConfigurationProperty ("security",
  201. Options = ConfigurationPropertyOptions.None)]
  202. public WebHttpSecurityElement Security {
  203. get { return (WebHttpSecurityElement) base [security]; }
  204. }
  205. [TypeConverter ()]
  206. [ConfigurationProperty ("writeEncoding",
  207. DefaultValue = "utf-8",
  208. Options = ConfigurationPropertyOptions.None)]
  209. public Encoding WriteEncoding {
  210. get { return (Encoding) base [write_encoding]; }
  211. set { base [write_encoding] = value; }
  212. }
  213. [ConfigurationProperty ("transferMode",
  214. DefaultValue = "Buffered",
  215. Options = ConfigurationPropertyOptions.None)]
  216. public TransferMode TransferMode {
  217. get { return (TransferMode) base [transfer_mode]; }
  218. set { base [transfer_mode] = value; }
  219. }
  220. [ConfigurationProperty ("useDefaultWebProxy",
  221. DefaultValue = true,
  222. Options = ConfigurationPropertyOptions.None)]
  223. public bool UseDefaultWebProxy {
  224. get { return (bool) base [use_default_web_proxy]; }
  225. set { base [use_default_web_proxy] = value; }
  226. }
  227. protected override void OnApplyConfiguration (Binding binding)
  228. {
  229. WebHttpBinding webBinding = (WebHttpBinding)binding;
  230. webBinding.AllowCookies = AllowCookies;
  231. webBinding.BypassProxyOnLocal = BypassProxyOnLocal;
  232. webBinding.HostNameComparisonMode = HostNameComparisonMode;
  233. webBinding.MaxBufferPoolSize = MaxBufferPoolSize;
  234. webBinding.MaxBufferSize = MaxBufferSize;
  235. webBinding.MaxReceivedMessageSize = MaxReceivedMessageSize;
  236. if(ProxyAddress != null)
  237. webBinding.ProxyAddress = ProxyAddress;
  238. webBinding.TransferMode = TransferMode;
  239. webBinding.UseDefaultWebProxy = UseDefaultWebProxy;
  240. webBinding.WriteEncoding = WriteEncoding;
  241. Security.ApplyConfiguration(webBinding.Security);
  242. }
  243. }
  244. }