WebHttpBinding.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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.ServiceModel.Channels;
  30. using System.Text;
  31. using System.Xml;
  32. namespace System.ServiceModel
  33. {
  34. public class WebHttpBinding
  35. #if NET_2_1
  36. : Binding
  37. #else
  38. : Binding, IBindingRuntimePreferences
  39. #endif
  40. {
  41. public WebHttpBinding ()
  42. : this (WebHttpSecurityMode.None)
  43. {
  44. }
  45. public WebHttpBinding (WebHttpSecurityMode mode)
  46. {
  47. security.Mode = mode;
  48. // MSDN says that this security mode can be set only
  49. // at .ctor(), so there is no problem on depending on
  50. // this value here.
  51. t = mode == WebHttpSecurityMode.Transport ? new HttpsTransportBindingElement () : new HttpTransportBindingElement ();
  52. t.ManualAddressing = true;
  53. }
  54. [MonoTODO]
  55. public WebHttpBinding (string configurationName)
  56. {
  57. throw new NotImplementedException ();
  58. }
  59. XmlDictionaryReaderQuotas quotas;
  60. WebHttpSecurity security = new WebHttpSecurity ();
  61. Encoding write_encoding = Encoding.UTF8;
  62. HttpTransportBindingElement t;
  63. // This can be changed only using <synchronousReceive> configuration element.
  64. bool receive_synchronously;
  65. public EnvelopeVersion EnvelopeVersion {
  66. get { return EnvelopeVersion.None; }
  67. }
  68. #if !NET_2_1
  69. public bool AllowCookies {
  70. get { return t.AllowCookies; }
  71. set { t.AllowCookies = value; }
  72. }
  73. public bool BypassProxyOnLocal {
  74. get { return t.BypassProxyOnLocal; }
  75. set { t.BypassProxyOnLocal = value; }
  76. }
  77. public HostNameComparisonMode HostNameComparisonMode {
  78. get { return t.HostNameComparisonMode; }
  79. set { t.HostNameComparisonMode = value; }
  80. }
  81. public long MaxBufferPoolSize {
  82. get { return t.MaxBufferPoolSize; }
  83. set { t.MaxBufferPoolSize = value; }
  84. }
  85. public TransferMode TransferMode {
  86. get { return t.TransferMode; }
  87. set { t.TransferMode = value; }
  88. }
  89. public bool UseDefaultWebProxy {
  90. get { return t.UseDefaultWebProxy; }
  91. set { t.UseDefaultWebProxy = value; }
  92. }
  93. public Uri ProxyAddress {
  94. get { return t.ProxyAddress; }
  95. set { t.ProxyAddress = value; }
  96. }
  97. #endif
  98. public int MaxBufferSize {
  99. get { return t.MaxBufferSize; }
  100. set { t.MaxBufferSize = value; }
  101. }
  102. public long MaxReceivedMessageSize {
  103. get { return t.MaxReceivedMessageSize; }
  104. set { t.MaxReceivedMessageSize = value; }
  105. }
  106. #if !NET_2_1
  107. public XmlDictionaryReaderQuotas ReaderQuotas {
  108. get { return quotas; }
  109. set { quotas = value; }
  110. }
  111. #endif
  112. public override string Scheme {
  113. get { return Security.Mode != WebHttpSecurityMode.None ? Uri.UriSchemeHttps : Uri.UriSchemeHttp; }
  114. }
  115. public WebHttpSecurity Security {
  116. get { return security; }
  117. }
  118. public Encoding WriteEncoding {
  119. get { return write_encoding; }
  120. set {
  121. if (value == null)
  122. throw new ArgumentNullException ("value");
  123. write_encoding = value;
  124. }
  125. }
  126. public override BindingElementCollection CreateBindingElements ()
  127. {
  128. WebMessageEncodingBindingElement m = new WebMessageEncodingBindingElement (WriteEncoding);
  129. #if !NET_2_1
  130. if (ReaderQuotas != null)
  131. ReaderQuotas.CopyTo (m.ReaderQuotas);
  132. #endif
  133. return new BindingElementCollection (new BindingElement [] { m, t.Clone () });
  134. }
  135. #if !NET_2_1
  136. bool IBindingRuntimePreferences.ReceiveSynchronously {
  137. get { return receive_synchronously; }
  138. }
  139. #endif
  140. }
  141. }