WCF Timeouts: To send or to receive, that is the question!

You decide to write a nice WCF service and you know the operation could take up to 5 minutes to complete. Well, what to do? What to do?

It is possible you say, well I well manually set the operation timeouts in code. That works but is annoying. How about setting the binding timeouts? There you go, nice and easy right?

Let’s take a look at the following binding:

<binding name="MyBinding" closeTimeout="00:00:30" openTimeout="00:00:30" receiveTimeout="00:05:00" sendTimeout="00:0:30">

It looks pretty accurate right? The operation takes 5 minutes or less, so it should work fine with the receiveTimeout being set to 5 minutes. No worries.

Well, YOUR WRONG!. Surprise!

The retarded illogical answer to the above quandary is that WCF uses the sendTimeout to figure out how long to wait to RECEIVE data. I know, painful. You will get timeout errors out the wazoo with the simple mixup of this little fact.

So, next time you setup your bindings, make sure to know the client really cares about the sendTimeout. It doesn’t seem to really concern itself with the receiveTimeout so much.

Here is the right binding:

<binding name="MyBinding" closeTimeout="00:00:30" openTimeout="00:00:30" receiveTimeout="00:05:00" sendTimeout="00:05:00" maxBufferSize="500000000" maxReceivedMessageSize="500000000">
 </binding>

Enjoy this little trickery and hopefully you save some time.

Happy coding!

Leave a Reply

Your email address will not be published. Required fields are marked *