Beispiel #1
0
        public override void CopyFrom(ServiceModelExtensionElement from)
        {
            base.CopyFrom(from);
            ServiceThrottlingElement element = (ServiceThrottlingElement)from;

            this.MaxConcurrentCalls     = element.MaxConcurrentCalls;
            this.MaxConcurrentSessions  = element.MaxConcurrentSessions;
            this.MaxConcurrentInstances = element.MaxConcurrentInstances;
        }
        public override void CopyFrom(ServiceModelExtensionElement from)
        {
            base.CopyFrom(from);

            ServiceThrottlingElement source = (ServiceThrottlingElement)from;

#pragma warning suppress 56506 //Microsoft; base.CopyFrom() checks for 'from' being null
            this.MaxConcurrentCalls     = source.MaxConcurrentCalls;
            this.MaxConcurrentSessions  = source.MaxConcurrentSessions;
            this.MaxConcurrentInstances = source.MaxConcurrentInstances;
        }
		public void ServiceThrottlingElement_defaults () {
			ServiceThrottlingElement element = new ServiceThrottlingElement ();

			Assert.AreEqual (typeof (ServiceThrottlingBehavior), element.BehaviorType, "BehaviorType");
			Assert.AreEqual ("serviceThrottling", element.ConfigurationElementName, "ConfigurationElementName");

			Assert.AreEqual (16, element.MaxConcurrentCalls, "MaxConcurrentCalls");
			Assert.AreEqual (10, element.MaxConcurrentSessions, "MaxConcurrentSessions");
			Assert.AreEqual (26, element.MaxConcurrentInstances, "MaxConcurrentInstances");
		}
Beispiel #4
0
        /// <summary>
        /// 获取启动服务参数
        /// </summary>
        /// <param name="implementsContractType">实体契约类的类型</param>
        /// <param name="interfaceContractType">契约类型</param>
        /// <param name="uri">服务地址</param>
        /// <param name="binding">启动服务类型</param>
        public void GetServiceConfig(Type implementsContractType, Type interfaceContractType, Uri uri, BindingType binding)
        {
            ImplementsContractType = implementsContractType;
            AddService(implementsContractType.ToString());
            ServiceEndpointElement item = new ServiceEndpointElement(uri, interfaceContractType.ToString());
            item.BindingConfiguration = item.Name = interfaceContractType.ToString();
            item.Binding = binding.ToString();

            ServiceElement service = serviceconfig.Services[implementsContractType.ToString()];
            service.Endpoints.Add(item);

            SetBindingParam(uri, binding, item.BindingConfiguration);

            if (!behaviorconfig.ServiceBehaviors.ContainsKey(service.BehaviorConfiguration))
            {
                ServiceBehaviorElement haviorelement = new ServiceBehaviorElement();// _setting.BehaviorConfig.ServiceBehaviors[service.BehaviorConfiguration];
                haviorelement.Name = service.BehaviorConfiguration;
                #region 并发设置
                //List<ServiceThrottlingElement> throttlingConfig = haviorelement.OfType<ServiceThrottlingElement>().ToList();
                ServiceThrottlingElement throttlingBehavior = new ServiceThrottlingElement();// host.Description.Behaviors.Find<ServiceThrottlingBehavior>();
                //当前ServiceHost能够处理的最大并发消息数量,默认值为16
                throttlingBehavior.MaxConcurrentCalls = int.MaxValue;
                //当前ServiceHost允许存在的InstanceContext的最大数量,默认值为26
                throttlingBehavior.MaxConcurrentInstances = int.MaxValue;
                //当前ServiceHost允许的最大并发会话数量,默认值为10
                throttlingBehavior.MaxConcurrentSessions = int.MaxValue;
                //throttlingConfig.Add(throttlingBehavior);
                haviorelement.Add(throttlingBehavior);
                #endregion

                #region 序列化最大项
                DataContractSerializerElement dataContractSerializerElement = new System.ServiceModel.Configuration.DataContractSerializerElement();
                dataContractSerializerElement.MaxItemsInObjectGraph = 2147483647;
                haviorelement.Add(dataContractSerializerElement);
                #endregion

                #region 是否充许客户端看到详细错误信息
                ServiceDebugElement debugConfig = new ServiceDebugElement();
                debugConfig.IncludeExceptionDetailInFaults = _isShowErrorInfoToClient;
                haviorelement.Add(debugConfig);
                #endregion

                behaviorconfig.ServiceBehaviors.Add(haviorelement);
            }
        }