How do I properly handle a faulted WCF connection?
Posted
by mafutrct
on Stack Overflow
See other posts from Stack Overflow
or by mafutrct
Published on 2010-03-20T11:51:21Z
Indexed on
2010/03/20
12:01 UTC
Read the original article
Hit count: 384
wcf
|faulted-connection
In my client program, there is a WCF connection that is opened at startup and supposedly stays connected til shutdown. However, there is a chance that the server closes due to unforeseeable circumstances (imagine someone pulling the cable).
Since the client uses a lot of contract methods in a lot of places, I don't want to add a try/catch on every method call.
I've got 2 ideas for handling this issue:
Create a method that takes a delegate and executes the delegate inside a try/catch and returns an Exception in case of a known exception, or null else. The caller has to deal with nun-null results.
Listen to the Faulted event of the underlying CommunicationObject. But I don't see how I could handle the event except for displaying some error message and shutting down.
Are there some best practices for faulted WCF connection that exist for app lifetime?
© Stack Overflow or respective owner