WCF: How do I add a ServiceThrottlingBehavior to a WCF Service?

房东的猫 提交于 2019-12-03 16:38:21

You can specify the behavior in the configuration file afaik, and the generated client will obey, using behaviors.

Some configuration sections excluded for brevity

<service 
    behaviorConfiguration="throttleThis" />

        <serviceBehaviors>
            <behavior name="throttleThis">
                <serviceMetadata httpGetEnabled="True" />
                <serviceThrottling
                    maxConcurrentCalls="40"
                    maxConcurrentInstances="20"
                    maxConcurrentSessions="20"/>
            </behavior>
        </serviceBehaviors>
Brian

Can be done in code for those, like me, who configure at runtime.

vb version:

    Dim stb As New ServiceThrottlingBehavior
    stb.MaxConcurrentSessions = 100
    stb.MaxConcurrentCalls = 100
    stb.MaxConcurrentInstances = 100
    ServiceHost.Description.Behaviors.Add(stb)

c# version:

    ServiceThrottlingBehavior stb = new ServiceThrottlingBehavior {
        MaxConcurrentSessions = 100,
        MaxConcurrentCalls = 100,
        MaxConcurrentInstances = 100
    };
    ServiceHost.Description.Behaviors.Add(stb);

Throttling is a service side (server) behavior not client side one

Arnon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!