• 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
        }



  • 相关阅读:
    HTML 照片从模糊到清晰的渐变加载显示方法
    Vue -- 从vue-cli 到@vue/cli 安装
    Vue -- highcharts map使用
    Vue -- admin
    EXCEL根据行列值查询得到交叉点值的方法
    如何使用curl命令测试负载均衡SLB会话保持的有效性
    centos7 pdsh安装
    selenium调用Chrome时自动选择证书
    jenkins使用 HTML Publisher插件后查看 html 报告显示不正常
    spring boot Jackson忽略字段不序列化字段
  • 原文地址:https://www.cnblogs.com/dyllove98/p/3190166.html
Copyright © 2020-2023  润新知