WCF Timeout issue - should there even be a socket connection?
- by stiank81
I have a .Net application which is split into a client and server side. The communication between them is handled using WCF. I'm not using the automagic service references, but instead I've built the connection manually like described in the Screencast by Miguel Castro. Summarized this means that I create a console application on the server side that holds ServiceHost objects for the different services:
var myServiceHost = new System.ServiceModel.ServiceHost(typeof(MyService), new Uri("net.tcp://localhost:8002"));
myServiceHost.Open();
And on the client side I have service proxies creating channels using the ChannelFactory:
IMyService proxy = new ChannelFactory<IMyService>("MyServiceEndpoint").CreateChannel();
The client and server side share the service contract defined in the interface IMyService. And another advantage is that I get minimal App.config files - without all the autogenerated stuff created through the Service References. Example from client side:
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<client>
<endpoint address="net.tcp://localhost:8002/MyEndpoint"
binding="netTcpBinding"
contract="IMyService"
name="MyServiceEndpoint"/>
</client>
</system.serviceModel>
</configuration>
So - to my problem. I create the proxy once, and it holds a channel all the way through the application. However, if I leave the application without use for a few minutes the channel has timed out, and I get the following exception:
The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:00:59.9979998'.
How do I prevent this? I'm assuming I need to specify a higher timeout in my configuration? But I don't want it to ever time out. But on the other hand - I don't want a socket connection! Do I need one? Thought I could go connection less with WCF...
What's the permanent solution and best practice on solving this?
Set timeout to "never"..
Create a new channel for each request? I'm assuming there is some overhead creating the channel?..
Increase the timeout to e.g. 5minutes and create new channel if the connection did timeout?
Make it connection less somehow? (Without the overhead of creating channels..)
Something else...