日期:2014-05-17  浏览次数:20897 次

wcf 并发问题


 <serviceThrottling maxConcurrentCalls="100" maxConcurrentInstances="100" maxConcurrentSessions="100"/>


为什么我改了 并发数 实例数 会话数   并发的操作一直是是只能10个呢。

我将maxConcurrentCalls改为5 可以控制5个并发 大于10就不行...用的是SL ...查了很多资料...没办法..

http://msdn.microsoft.com/zh-cn/library/ms752260.aspx

------解决方案--------------------
自己写一个Attribute配置类,继承Attribute与IServiceBehavior接口

MaxConcurrentCalls //正在处理的最多消息数
MaxConcurrentInstances //服务中可以一次执行的最多 System.ServiceModel.InstanceContext 对象数
MaxConcurrentSessions //对象可一次接受的最多会话数的值


using System;
using System.Collections.ObjectModel;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;

/// <summary>
    /// 吞吐量配置实类
    /// </summary>
    public class ServiceThrottlingAttribute : Attribute, IServiceBehavior
    {
        private ServiceThrottlingBehavior Throttling;

        /// <summary>
        /// 实例化 ServiceThrottlingAttribute 新的实例
        /// </summary>
        public ServiceThrottlingAttribute()
            : this(64, System.Int32.MaxValue, 10)
        {

        }

        /// <summary>
        /// 实例化 ServiceThrottlingAttribute 新的实例
        /// </summary>
        /// <param name="maxConcurrentCalls">指定整个 System.ServiceModel.ServiceHost 中正在处理的最多消息数</param>
        /// <param name="maxConcurrentInstances">指定服务中可以一次执行的最多 System.ServiceModel.InstanceContext 对象数</param>
        /// <param name="maxConcurrentSessions">指定 System.ServiceModel.ServiceHost 对象可一次接受的最多会话数的值</param>
        public ServiceThrottlingAttribute(int maxConcurrentCalls, int maxConcurrentInstances, int maxConcurrentSessions)
        {
            this.Throttling = new ServiceThrottlingBehavior();
            this.MaxConcurrentCalls = maxConcurrentCalls;
            this.MaxConcurrentInstances = maxConcurrentInstances;
            this.MaxConcurrentSessions = maxConcurrentSessions;
        }

        /// <summary>
        /// 获取或设置一个值,该值指定整个 System.ServiceModel.ServiceHost 中正在处理的最多消息数(默认