I’ve been working on a WCF service for distributing file updates. Recently I did some testing to see how well the system performs through slow connections and discovered some issues I’m glad I run into before the release.
My first discovery was that WCF (using a streaming net.tcp binding) does not perform very well with high ping round-trip-times. In this case my first test setup was quite extreme, as I connected to the service using VPN through a WLAN router connected to the internet by 3G. The ping was something around 750ms.
My second discovery was that the default SendTimeout for a service is 1 minute. This is not nearly enough for a service returning files! I believe the default timeout will cause problems even with fast connections as it only depends on the size of the largest file. If the operation is still returning data after 1 minute, the server closes the stream without warning and returning just some timeout or IO exception.
Fortunately fixing the issue was easy, I just needed to increase the SendTimeout of the service:
binding.SendTimeout = new TimeSpan(1, 0, 0); // 1 hour
If you change the SendTimeout, you should also consider increasing the default 10 minute ReceiveTimeout of the client binding.
There is of course a small security risk in incresing the timeouts, but in my case it’s ok as my service will only be used in a internal network. I wonder if there is a way to define an operation specific SendTimeout?