技术开发 频道

Programming WCF Services:分步操作、实例停用与限流


定义的ServiceThrottlingAttribute特性继承了Attribute,并实现了IServiceBehavior接口。在特性内,则使用了ServiceThrottlingBehavior类,以设置限流的相关值。如果要配置服务的限流值,就可以应用该特性,例如:
[ServiceThrottling(12, 34, 56)]
class MyService : IMyContract,IDisposable
{
public void MyMethod( )
{
ChannelDispatcher dispatcher = OperationContext.Current.Host.ChannelDispatchers[0] as ChannelDispatcher;
ServiceThrottle serviceThrottle = dispatcher.ServiceThrottle;

Trace.WriteLine("MaxConcurrentCalls = " + serviceThrottle.MaxConcurrentCalls);
Trace.WriteLine("MaxSessions = " + serviceThrottle.MaxConcurrentSessions);
Trace.WriteLine("MaxInstances = " + serviceThrottle.MaxConcurrentInstances);
}
}
则输出结果为:
MaxConcurrentCalls = 12 
MaxSessions = 56
MaxInstances = 34


0
相关文章