since I couldn't find the appropriate answer to my question in a couple hours, I'm posting it here.
I have a WPF/WCF application with shared interface (IService) library and dynamically created proxies (created with CreateChannel). The main problem is that proxies are not being closed/disposed and I'm getting this exception at 200-th service call:
The system hit the limit set for throttle 'MaxConcurrentSessions'. Limit for this throttle was set to 200. Throttle value can be changed by modifying attribute 'maxConcurrentSessions' in serviceThrottle element or by modifying 'MaxConcurrentSessions' property on behavior ServiceThrottlingBehavior.
Interestingly, the same proxy works fine with BasicHttpBinding!
It seems that NetNamedPipeBinding proxies are not being closed and disposed automatically. Here are some client side code snippets.
// creation of ChannelFactory - only one for each service interface
public static ChannelFactory<T> CreateChannelFactory(string serviceAddress)
{
Binding binding = new NetNamedPipeBinding()
{
// setting quotas and timeouts
};
ChannelFactory<T> factory = new ChannelFactory<T>(binding, new EndpointAddress(serviceAddress));
factory.Endpoint.Behaviors.Add(new AuthenticationBehavior()); // custom IEndpointBehavior
foreach (OperationDescription op in factory.Endpoint.Contract.Operations)
{
DataContractSerializerOperationBehavior dataContractBehavior = op.Behaviors.Find<DataContractSerializerOperationBehavior>() as DataContractSerializerOperationBehavior;
if (dataContractBehavior != null)
{
dataContractBehavior.MaxItemsInObjectGraph = 2147483647;
}
}
return factory;
}
public static T GetService()
{
// simplified - actually holding a collection of CFs and creating each factory only once
return ChannelFactoryHelper<T>.CreateChannelFactory(serviceAddress).CreateChannel();
}
// creation of the proxy - new for each WCF call
IService svc = ServiceHelper<IService>.GetService();
... // calling the service
You can see I'm not using the "using" statement, since the proxy doesn't implement IDisposable. First question is, how would I do that. On the client side, I'm using the IService as a proxy type. If I wanted the IService to be IDisposable, I'd have to implement the dispose method on the service side - since my Service implements IService. That doesn't seem logical - to call service method to dispose that service...
Since It'd be better not to change all code for service calls to "using": is there any way to auto dispose the proxy when not in use anymore? Why is that not done automatically? Please note that I'm using custom IExtensionBehavior - could that be the reason?
Any help would be appreciated. Thank you!