PageRenderTime 27ms CodeModel.GetById 22ms app.highlight 2ms RepoModel.GetById 2ms app.codeStats 0ms

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

#
C# | 94 lines | 60 code | 9 blank | 25 comment | 12 complexity | dac6b7b76e26c95bb0e03f2fbb996996 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.ServiceModel;
 9    using System.ServiceModel.Channels;
10    using System.ServiceModel.Description;
11    using System.ServiceModel.Dispatcher;
12    using Microsoft.ApplicationServer.Http;
13    using Microsoft.Server.Common;
14
15    /// <summary>
16    /// Class that provides <see cref="IEndpointBehavior"/> for the <see cref="HttpMemoryBinding"/> binding.
17    /// </summary>
18    internal class HttpMemoryBehavior : IEndpointBehavior
19    {
20        private static readonly Type httpMemoryBehaviorType = typeof(HttpMemoryBehavior);
21
22        /// <summary>
23        /// Passes data at runtime to bindings to support custom behavior.
24        /// </summary>
25        /// <param name="endpoint">The endpoint to modify.</param>
26        /// <param name="bindingParameters">The objects that binding elements require to support the behavior.</param>
27        public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
28        {
29            if (endpoint == null)
30            {
31                throw Fx.Exception.ArgumentNull("endpoint");
32            }
33
34            if (bindingParameters == null)
35            {
36                throw Fx.Exception.ArgumentNull("bindingParameters");
37            }
38        }
39
40        /// <summary>
41        /// Implements a modification or extension of the client across an endpoint.
42        /// </summary>
43        /// <param name="endpoint">The endpoint that is to be customized.</param>
44        /// <param name="clientRuntime">The client runtime to be customized.</param>
45        public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
46        {
47            throw Fx.Exception.AsError(
48                new NotSupportedException(SR.ApplyClientBehaviorNotSupportedByBehavior(httpMemoryBehaviorType.Name)));
49        }
50
51        /// <summary>
52        /// Implements a modification or extension of the service across an endpoint.
53        /// </summary>
54        /// <param name="endpoint">The endpoint that exposes the contract.</param>
55        /// <param name="endpointDispatcher">The endpoint dispatcher to be modified or extended.</param>
56        public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
57        {
58            if (endpoint == null)
59            {
60                throw new ArgumentNullException("endpoint");
61            }
62
63            if (endpointDispatcher == null)
64            {
65                throw new ArgumentNullException("endpointDispatcher");
66            }
67
68            foreach (OperationDescription operationDescription in endpoint.Contract.Operations)
69            {
70                OperationBehaviorAttribute operationBehavior = operationDescription.Behaviors.Find<OperationBehaviorAttribute>();
71                if (operationBehavior == null)
72                {
73                    operationDescription.Behaviors.Add(new OperationBehaviorAttribute { AutoDisposeParameters = false });
74                }
75                else
76                {
77                    operationBehavior.AutoDisposeParameters = false;
78                }
79            }
80        }
81
82        /// <summary>
83        /// Confirms that the endpoint meets some intended criteria.
84        /// </summary>
85        /// <param name="endpoint">The endpoint to validate.</param>
86        public void Validate(ServiceEndpoint endpoint)
87        {
88            if (endpoint == null)
89            {
90                throw Fx.Exception.ArgumentNull("endpoint");
91            }
92        }
93    }
94}