PageRenderTime 26ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/WCFWebApi/src/Microsoft.ApplicationServer.Http/Microsoft/ApplicationServer/Http/Description/HttpEndpoint.cs

#
C# | 186 lines | 113 code | 19 blank | 54 comment | 10 complexity | 608be3a978fc8beecc02d6e6d201798e MD5 | raw file
Possible License(s): CC-BY-SA-3.0, Apache-2.0
  1. // <copyright>
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. // </copyright>
  4. namespace Microsoft.ApplicationServer.Http.Description
  5. {
  6. using System;
  7. using System.ComponentModel;
  8. using System.ServiceModel;
  9. using System.ServiceModel.Description;
  10. using Microsoft.ApplicationServer.Http.Channels;
  11. using Microsoft.Server.Common;
  12. /// <summary>
  13. /// Class that provides a <see cref="ServiceEndpoint"/> for the <see cref="HttpBinding"/> binding.
  14. /// </summary>
  15. public class HttpEndpoint : ServiceEndpoint
  16. {
  17. internal const string Kind = "httpEndpoint";
  18. /// <summary>
  19. /// Initializes a new instance of the <see cref="HttpEndpoint"/> class.
  20. /// </summary>
  21. /// <param name="contract">The <see cref="ContractDescription"/> for the service endpoint.</param>
  22. public HttpEndpoint(ContractDescription contract)
  23. : this(contract, null)
  24. {
  25. }
  26. /// <summary>
  27. /// Initializes a new instance of the <see cref="HttpEndpoint"/> class.
  28. /// </summary>
  29. /// <param name="contract">The <see cref="ContractDescription"/> for the service endpoint.</param>
  30. /// <param name="address">The <see cref="EndpointAddress"/> for the service endpoint.</param>
  31. public HttpEndpoint(ContractDescription contract, EndpointAddress address)
  32. : base(contract, new HttpBinding(), address)
  33. {
  34. this.Behaviors.Add(new HttpBehavior());
  35. if (address != null && address.Uri != null && address.Uri.Scheme == Uri.UriSchemeHttps)
  36. {
  37. this.Security.Mode = HttpBindingSecurityMode.Transport;
  38. }
  39. }
  40. /// <summary>
  41. /// Gets or sets the default <see cref="HttpMessageHandlerFactory"/> to use for
  42. /// the <see cref="HttpEndpoint"/>.
  43. /// </summary>
  44. public HttpMessageHandlerFactory MessageHandlerFactory
  45. {
  46. get { return this.HttpBinding.MessageHandlerFactory; }
  47. set { this.HttpBinding.MessageHandlerFactory = value; }
  48. }
  49. /// <summary>
  50. /// Gets or sets the default <see cref="HttpOperationHandlerFactory"/> to use for
  51. /// the <see cref="HttpEndpoint"/>.
  52. /// </summary>
  53. [DefaultValue(null)]
  54. public HttpOperationHandlerFactory OperationHandlerFactory
  55. {
  56. get { return this.HttpBehavior.OperationHandlerFactory; }
  57. set { this.HttpBehavior.OperationHandlerFactory = value; }
  58. }
  59. /// <summary>
  60. /// Gets or sets a value specifying how the host name should be use in <see cref="Uri"/>
  61. /// comparisons when dispatching an incoming message to a service endpoint.
  62. /// </summary>
  63. public HostNameComparisonMode HostNameComparisonMode
  64. {
  65. get { return this.HttpBinding.HostNameComparisonMode; }
  66. set { this.HttpBinding.HostNameComparisonMode = value; }
  67. }
  68. /// <summary>
  69. /// Gets or sets the maximum amount of memory that is allocated for use by the manager
  70. /// of the message buffers that receive messages from the endpoint.
  71. /// </summary>
  72. public long MaxBufferPoolSize
  73. {
  74. get { return this.HttpBinding.MaxBufferPoolSize; }
  75. set { this.HttpBinding.MaxBufferPoolSize = value; }
  76. }
  77. /// <summary>
  78. /// Gets or sets the maximum amount of memory that is allocated for use by the manager of the message
  79. /// buffers that receive messages from the channel.
  80. /// </summary>
  81. public int MaxBufferSize
  82. {
  83. get { return this.HttpBinding.MaxBufferSize; }
  84. set { this.HttpBinding.MaxBufferSize = value; }
  85. }
  86. /// <summary>
  87. /// Gets or sets the maximum size for a message that can be processed by the endpoint.
  88. /// </summary>
  89. public long MaxReceivedMessageSize
  90. {
  91. get { return this.HttpBinding.MaxReceivedMessageSize; }
  92. set { this.HttpBinding.MaxReceivedMessageSize = value; }
  93. }
  94. /// <summary>
  95. /// Gets or sets a value that indicates whether the service configured with the endpoint uses streamed or
  96. /// buffered (or both) modes of message transfer.
  97. /// </summary>
  98. public TransferMode TransferMode
  99. {
  100. get { return this.HttpBinding.TransferMode; }
  101. set { this.HttpBinding.TransferMode = value; }
  102. }
  103. /// <summary>
  104. /// Gets the <see cref="HttpBindingSecurity"/> for this endpoint.
  105. /// </summary>
  106. public HttpBindingSecurity Security
  107. {
  108. get { return this.HttpBinding.Security; }
  109. }
  110. /// <summary>
  111. /// Gets or sets a value indicating whether an automatic help page will be generated.
  112. /// </summary>
  113. public bool HelpEnabled
  114. {
  115. get { return this.HttpBehavior.HelpEnabled; }
  116. set { this.HttpBehavior.HelpEnabled = value; }
  117. }
  118. /// <summary>
  119. /// Gets or sets a value indicating whether a web-based test client will be generated.
  120. /// </summary>
  121. public bool TestClientEnabled
  122. {
  123. get { return this.HttpBehavior.TestClientEnabled; }
  124. set { this.HttpBehavior.TestClientEnabled = value; }
  125. }
  126. /// <summary>
  127. /// Gets or sets a value specifying how trailing slashes on <see cref="Uri"/>s should be treated.
  128. /// </summary>
  129. public TrailingSlashMode TrailingSlashMode
  130. {
  131. get { return this.HttpBehavior.TrailingSlashMode; }
  132. set { this.HttpBehavior.TrailingSlashMode = value; }
  133. }
  134. internal HttpBinding HttpBinding
  135. {
  136. get
  137. {
  138. HttpBinding localHttpBinding = this.Binding as HttpBinding;
  139. if (localHttpBinding == null)
  140. {
  141. throw Fx.Exception.AsError(
  142. new InvalidOperationException(
  143. Http.SR.HttpEndpointRequiresHttpBinding(
  144. typeof(HttpEndpoint).Name,
  145. typeof(HttpBinding).Name)));
  146. }
  147. return localHttpBinding;
  148. }
  149. }
  150. internal HttpBehavior HttpBehavior
  151. {
  152. get
  153. {
  154. HttpBehavior localHttpBehavior = this.Behaviors.Find<HttpBehavior>();
  155. if (localHttpBehavior == null)
  156. {
  157. throw Fx.Exception.AsError(
  158. new InvalidOperationException(
  159. Http.SR.HttpBehaviorNotFoundWithEndpoint(
  160. typeof(HttpEndpoint).Name,
  161. typeof(HttpBehavior).Name)));
  162. }
  163. return localHttpBehavior;
  164. }
  165. }
  166. }
  167. }