如何获取和设置WCF服务器线程池中允许并行处理传入请求的线程数?
我正在使用WebHttpBinding。
答案 0 :(得分:3)
您可以通过ServiceThrottlingBehavior
类获取它们,默认值如下
.NET 3.0 / 3.5
.NET 4.0 +
你最感兴趣的是MaxConcurrentInstances
,因为这会消耗一个线程。通常,如果您在何处配置它,则应在app.config文件中进行设置
<configuration>
<appSettings>
<!-- use appSetting to configure base address provided by host -->
<add key="baseAddress" value="http://localhost:8080/ServiceMetadata" />
</appSettings>
<system.serviceModel>
<services>
<service
name="Microsoft.WCF.Documentation.SampleService"
behaviorConfiguration="Throttled" >
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/SampleService"/>
</baseAddresses>
</host>
<endpoint
address=""
binding="wsHttpBinding"
contract="Microsoft.WCF.Documentation.ISampleService"
/>
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"
/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="Throttled">
<serviceThrottling
maxConcurrentCalls="1"
maxConcurrentSessions="1"
maxConcurrentInstances="1"
/>
<serviceMetadata
httpGetEnabled="true"
httpGetUrl=""
/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
通过代码查找起来要困难得多(我无法弄明白,我通常只使用配置文件)