zoukankan      html  css  js  c++  java
  • WCF 项目应用连载[8]


    因为ORM的原因,对Attribute编程有一种情节。。所以这节的出现,完全是因为在WCF对自定义Attribute的一种应用。


    WCF 项目应用连载[7] - 绑定、服务、行为 大数据传输与限流 - 上


    前面一节已经讲得差不多够了。


    对WCF的限流,这节,提供一个类。ServiceThrottlingAttribute


    让你以硬编码方式使用WCF服务限流

        [ServiceThrottling(50,200,100)]
        [ServiceContract(CallbackContract = typeof(ILigAgentCallback))]
        public interface ILigAgent


    public class ServiceThrottlingAttribute : Attribute,IServiceBehavior
        {
            #region Constructors
            public ServiceThrottlingAttribute()
                : this(defaultCalls, defaultInstances, defaultSession)
            {
            }
    
            public ServiceThrottlingAttribute(int maxCalls, int maxInstances, int maxSessions)
            {
                this.Initialize(maxCalls, maxInstances, maxSessions);
            }
            #endregion
    
            #region Interfaces
            /// <summary>
            /// 
            /// </summary>
            /// <param name="serviceDescriptiong"></param>
            /// <param name="serviceHostBase"></param>
            /// <param name="endpoints"></param>
            /// <param name="bindingParameters"></param>
            void IServiceBehavior.AddBindingParameters(ServiceDescription serviceDescriptiong, ServiceHostBase serviceHostBase,
                Collection<ServiceEndpoint> endpoints, BindingParameterCollection bindingParameters)
            {
            }
    
            /// <summary>
            /// 
            /// </summary>
            /// <param name="serviceDescription"></param>
            /// <param name="serviceHostBase"></param>
            void IServiceBehavior.ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
            {
                ServiceThrottlingBehavior tbehavior = serviceDescription.Behaviors.Find<ServiceThrottlingBehavior>();
                if (tbehavior == null)
                {
                    serviceDescription.Behaviors.Add(this.throttlingBehavior);
                }
            }
    
            /// <summary>
            /// 
            /// </summary>
            /// <param name="serviceDescription"></param>
            /// <param name="serviceHostBase"></param>
            void IServiceBehavior.Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
            {
    
            }
            #endregion
    
            #region Private Helpers
            private void Initialize(int maxCalls, int maxInstances, int maxSessions)
            {
                this.throttlingBehavior = new ServiceThrottlingBehavior();
                this.throttlingBehavior.MaxConcurrentCalls = maxCalls;
                this.throttlingBehavior.MaxConcurrentInstances = maxInstances;
                this.throttlingBehavior.MaxConcurrentSessions = maxSessions;
            }
            #endregion
    
            #region Fields
            private const int defaultThrottling = 50;
            private const int defaultCalls = 50;
            private const int defaultInstances = 200;
            private const int defaultSession = 100;
            private ServiceThrottlingBehavior throttlingBehavior = null;
            #endregion
        }



  • 相关阅读:
    MATLAB 之 App designer 小白学习(四)
    MATLAB 之 APP DESIGNER 学习(三)
    MATLAB 之 App designer 小白学习(二)
    MATLAB 之 App designer 小白学习(一)
    激光烧蚀 @有机聚合物
    激光驱动巨量转移工艺
    基于神经网络的函数逼近
    单片机复位电路仿真分析
    基于Python的3R机器人运动仿真
    基于MATLAB的单级倒立摆仿真
  • 原文地址:https://www.cnblogs.com/dyllove98/p/3190166.html
Copyright © 2011-2022 走看看