WebHttpBinding.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. WebHttpSecurity security = new WebHttpSecurity ();
  60. HttpTransportBindingElement t;
  61. // This can be changed only using <synchronousReceive> configuration element.
  62. bool receive_synchronously;
  63. WebMessageEncodingBindingElement msgenc = new WebMessageEncodingBindingElement ();
  64. public EnvelopeVersion EnvelopeVersion {
  65. get { return EnvelopeVersion.None; }
  66. }
  67. #if !NET_2_1
  68. public bool AllowCookies {
  69. get { return t.AllowCookies; }
  70. set { t.AllowCookies = value; }
  71. }
  72. public bool BypassProxyOnLocal {
  73. get { return t.BypassProxyOnLocal; }
  74. set { t.BypassProxyOnLocal = value; }
  75. }
  76. #if NET_4_0
  77. [MonoTODO]
  78. public bool CrossDomainScriptAccessEnabled { get; set; }
  79. public WebContentTypeMapper ContentTypeMapper {
  80. get { return msgenc.ContentTypeMapper; }
  81. set { msgenc.ContentTypeMapper = value; }
  82. }
  83. #endif
  84. public HostNameComparisonMode HostNameComparisonMode {
  85. get { return t.HostNameComparisonMode; }
  86. set { t.HostNameComparisonMode = value; }
  87. }
  88. public long MaxBufferPoolSize {
  89. get { return t.MaxBufferPoolSize; }
  90. set { t.MaxBufferPoolSize = value; }
  91. }
  92. public TransferMode TransferMode {
  93. get { return t.TransferMode; }
  94. set { t.TransferMode = value; }
  95. }
  96. public bool UseDefaultWebProxy {
  97. get { return t.UseDefaultWebProxy; }
  98. set { t.UseDefaultWebProxy = value; }
  99. }
  100. public Uri ProxyAddress {
  101. get { return t.ProxyAddress; }
  102. set { t.ProxyAddress = value; }
  103. }
  104. #endif
  105. public int MaxBufferSize {
  106. get { return t.MaxBufferSize; }
  107. set { t.MaxBufferSize = value; }
  108. }
  109. public long MaxReceivedMessageSize {
  110. get { return t.MaxReceivedMessageSize; }
  111. set { t.MaxReceivedMessageSize = value; }
  112. }
  113. #if !NET_2_1
  114. public XmlDictionaryReaderQuotas ReaderQuotas {
  115. get { return msgenc.ReaderQuotas; }
  116. set { msgenc.ReaderQuotas = value; }
  117. }
  118. #endif
  119. public override string Scheme {
  120. get { return Security.Mode != WebHttpSecurityMode.None ? Uri.UriSchemeHttps : Uri.UriSchemeHttp; }
  121. }
  122. public WebHttpSecurity Security {
  123. get { return security; }
  124. }
  125. public Encoding WriteEncoding {
  126. get { return msgenc.WriteEncoding; }
  127. set {
  128. if (value == null)
  129. throw new ArgumentNullException ("value");
  130. msgenc.WriteEncoding = value;
  131. }
  132. }
  133. public override BindingElementCollection CreateBindingElements ()
  134. {
  135. return new BindingElementCollection (new BindingElement [] { msgenc, t.Clone () });
  136. }
  137. #if !NET_2_1
  138. bool IBindingRuntimePreferences.ReceiveSynchronously {
  139. get { return receive_synchronously; }
  140. }
  141. #endif
  142. }
  143. }