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