WebHttpBinding.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. //
  2. // WebHttpBinding.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.ComponentModel;
  30. using System.ServiceModel.Channels;
  31. using System.Text;
  32. using System.Xml;
  33. namespace System.ServiceModel
  34. {
  35. public class WebHttpBinding
  36. #if NET_2_1
  37. : Binding
  38. #else
  39. : Binding, IBindingRuntimePreferences
  40. #endif
  41. {
  42. public WebHttpBinding ()
  43. : this (WebHttpSecurityMode.None)
  44. {
  45. }
  46. public WebHttpBinding (WebHttpSecurityMode mode)
  47. {
  48. security.Mode = mode;
  49. // MSDN says that this security mode can be set only
  50. // at .ctor(), so there is no problem on depending on
  51. // this value here.
  52. t = mode == WebHttpSecurityMode.Transport ? new HttpsTransportBindingElement () : new HttpTransportBindingElement ();
  53. t.ManualAddressing = true;
  54. }
  55. [MonoTODO]
  56. public WebHttpBinding (string configurationName)
  57. {
  58. throw new NotImplementedException ();
  59. }
  60. WebHttpSecurity security = new WebHttpSecurity ();
  61. HttpTransportBindingElement t;
  62. // This can be changed only using <synchronousReceive> configuration element.
  63. bool receive_synchronously;
  64. WebMessageEncodingBindingElement msgenc = new WebMessageEncodingBindingElement ();
  65. public EnvelopeVersion EnvelopeVersion {
  66. get { return EnvelopeVersion.None; }
  67. }
  68. #if !NET_2_1
  69. #if NET_4_0
  70. [DefaultValue (false)]
  71. #endif
  72. public bool AllowCookies {
  73. get { return t.AllowCookies; }
  74. set { t.AllowCookies = value; }
  75. }
  76. #if NET_4_0
  77. [DefaultValue (false)]
  78. #endif
  79. public bool BypassProxyOnLocal {
  80. get { return t.BypassProxyOnLocal; }
  81. set { t.BypassProxyOnLocal = value; }
  82. }
  83. #if NET_4_0
  84. [MonoTODO]
  85. public bool CrossDomainScriptAccessEnabled { get; set; }
  86. public WebContentTypeMapper ContentTypeMapper {
  87. get { return msgenc.ContentTypeMapper; }
  88. set { msgenc.ContentTypeMapper = value; }
  89. }
  90. #endif
  91. #if NET_4_0
  92. [DefaultValue (HostNameComparisonMode.StrongWildcard)]
  93. #endif
  94. public HostNameComparisonMode HostNameComparisonMode {
  95. get { return t.HostNameComparisonMode; }
  96. set { t.HostNameComparisonMode = value; }
  97. }
  98. #if NET_4_0
  99. [DefaultValue (0x10000)]
  100. #endif
  101. public long MaxBufferPoolSize {
  102. get { return t.MaxBufferPoolSize; }
  103. set { t.MaxBufferPoolSize = value; }
  104. }
  105. #if NET_4_0
  106. [DefaultValue (TransferMode.Buffered)]
  107. #endif
  108. public TransferMode TransferMode {
  109. get { return t.TransferMode; }
  110. set { t.TransferMode = value; }
  111. }
  112. #if NET_4_0
  113. [DefaultValue (true)]
  114. #endif
  115. public bool UseDefaultWebProxy {
  116. get { return t.UseDefaultWebProxy; }
  117. set { t.UseDefaultWebProxy = value; }
  118. }
  119. #if NET_4_0
  120. [DefaultValue (null)]
  121. #endif
  122. public Uri ProxyAddress {
  123. get { return t.ProxyAddress; }
  124. set { t.ProxyAddress = value; }
  125. }
  126. #endif
  127. #if NET_4_0
  128. [DefaultValue (0x80000)]
  129. #endif
  130. public int MaxBufferSize {
  131. get { return t.MaxBufferSize; }
  132. set { t.MaxBufferSize = value; }
  133. }
  134. #if NET_4_0
  135. [DefaultValue (0x10000)]
  136. #endif
  137. public long MaxReceivedMessageSize {
  138. get { return t.MaxReceivedMessageSize; }
  139. set { t.MaxReceivedMessageSize = value; }
  140. }
  141. public XmlDictionaryReaderQuotas ReaderQuotas {
  142. get { return msgenc.ReaderQuotas; }
  143. set { msgenc.ReaderQuotas = value; }
  144. }
  145. public override string Scheme {
  146. get { return Security.Mode != WebHttpSecurityMode.None ? Uri.UriSchemeHttps : Uri.UriSchemeHttp; }
  147. }
  148. public WebHttpSecurity Security {
  149. get { return security; }
  150. #if NET_4_0
  151. set {
  152. if (value == null)
  153. throw new ArgumentNullException ("value");
  154. security = value;
  155. }
  156. #endif
  157. }
  158. public Encoding WriteEncoding {
  159. get { return msgenc.WriteEncoding; }
  160. set {
  161. if (value == null)
  162. throw new ArgumentNullException ("value");
  163. msgenc.WriteEncoding = value;
  164. }
  165. }
  166. public override BindingElementCollection CreateBindingElements ()
  167. {
  168. return new BindingElementCollection (new BindingElement [] { msgenc, t.Clone () });
  169. }
  170. #if !NET_2_1
  171. bool IBindingRuntimePreferences.ReceiveSynchronously {
  172. get { return receive_synchronously; }
  173. }
  174. #endif
  175. #if NET_4_0
  176. [EditorBrowsable (EditorBrowsableState.Advanced)]
  177. public bool ShouldSerializeReaderQuotas ()
  178. {
  179. return false;
  180. }
  181. [EditorBrowsable (EditorBrowsableState.Advanced)]
  182. public bool ShouldSerializeSecurity ()
  183. {
  184. return false;
  185. }
  186. [EditorBrowsable (EditorBrowsableState.Advanced)]
  187. public bool ShouldSerializeWriteEncoding ()
  188. {
  189. return false;
  190. }
  191. #endif
  192. }
  193. }