WebHttpBinding.cs 4.2 KB

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