How can I ensure that a WCF service uses threads from a ThreadPool to process incoming messages?
At the moment simple method invocation like 'return null;' takes about 45 seconds while another requests are processing
Here is how I have annotated my service class:
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.Single)]
public partial class MyService : IMyService {
...
}
But when I'm watching the process in task manager it seems to be using a constant number of threads. Even under load.
public ActionResult SelectDatabase(string param)
{
if (!String.IsNullOrEmpty(param))
{
try
{
MyServicece svc = new MyService();
Database[] dbsArray = svc.GetDatabases(param);
if (depsArray != null)
ViewData["depsArray"] = depsArray;
return View();
}
catch (Exception exc)
{
// log here
return ActionUnavailable();
}
}
Here is my service behavior:
<?xml version="1.0"?>
<configuration>
<runtime>
</runtime>
<system.net>
<connectionManagement>
<add address="*" maxconnection="100" />
</connectionManagement>
</system.net>
<system.serviceModel>
<diagnostics performanceCounters="Default" />
<bindings>
<netTcpBinding>
<binding sendTimeout="00:02:00" receiveTimeout="00:02:00" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647">
<security mode="None">
</security>
</binding>
</netTcpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<behaviors>
<endpointBehaviors>
<behavior name="CrossDomainServiceBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="MyService.MyServiceBehavior">
<serviceThrottling maxConcurrentCalls="100" maxConcurrentInstances="100" maxConcurrentSessions="100" />
<dataContractSerializer maxItemsInObjectGraph="2147483646"/>
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="MyService.MyServiceBehavior" name="MyService.MyService">
<endpoint address="MyService" binding="netTcpBinding" contract="AService.IAServ" isSystemEndpoint="false" />
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
</service>
<service behaviorConfiguration="MyService.MyServiceBehavior" name="MyService.MyServiceAdmin">
<endpoint address="MyServiceAdmin" binding="netTcpBinding" contract="MyService.IMyServiceAdmin" isSystemEndpoint="false" />
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
Here is how I create service instance:
ServiceHost myserviceHost = new ServiceHost(typeof(MyService), new Uri(String.Format("net.tcp://{0}/", _bindAddress)));
myserviceHost.Open();
Console.WriteLine(myserviceHost.BaseAddresses[0]);