Web Dev
Web Dev

Reputation: 2937

WCF timeout handling

We are currently developing a software solution which has a client and a number of WCF services that it consumes. The issues we are having is WCF services timing out after a period of inactivity. As far as I understand, there are 2 ways to resolve this:

  1. Increase timeouts (as far as I understood, this is generally not recommended. Eg. setting timeout to infinite/weeks is considered bad practice)
  2. Periodically ping the WCF services from the Client (I'm not sure that I'm a huge fan of his as it will add redundant, periodic calls)
  3. Handle timeout issues and attempt to reconnect (this is slow and requires a lot of manual code)
  4. Reliable Sessions - some sources mention that this is the in-built WCF pinging and message reliability mechanism, but other sources mention that this will still time out.

What is the recommended/best way of resolving this issue? Is there any official reading material on this? I could not find all that much info myself

Thanks!

Upvotes: 0

Views: 718

Answers (2)

Rabban
Rabban

Reputation: 2581

As i can see, you have to use a combination of your stated points.

  1. You are right, increasing the timeouts is bad practice and can give you a lot of problems.
  2. If you don't want to use Reliable Sessions, then Ping is the only applicable way to hold the connection.
  3. You need to handle this things, no matter if a timeout occurs, the connection is lost or a exception is thrown. There are a plenty of possibilities that your connection can fault.
  4. Reliable Sessions are a good way not to implement a ping, but technically, it does nearly the same. WCF automatically sends an "I am still here" Request.

The conclusion of this is, that you need point 3 and point 2 or 4. To reduce the manually code for point 3, you can use Proxies or a wrapper around your ServiceClient, that establishes a new connection if the old one is faulted during a request. Point 4 is easy to implement, because you only need some small additions to your binding in your config. And the traffic overhead is not that big. Point 2 is the most expensive way, you need to handle a Thread/Task that only pings the server and the service needs to be extended. But as you stated before, Reliable Sessions can fail, and Pings should bring you on the safe side.

Upvotes: 2

Travis Primm
Travis Primm

Reputation: 179

You should ask yourself what is your WCF endpoint is doing? Is the way you have your command setup the most optimal? Perhaps it'd be better to have your endpoint that takes a long time be based on a polling system that allows there to be a quick query instead of waiting on the results of the endpoints actions. You should also consider data transfer as a possible issue. Is the amount of data you're transferring back a lot?

To get a more pointed answer, we'd need to know more about the specific endpoint as well as any other responsibilities there are for the service.

Upvotes: 1

Related Questions