I'm using a client-side proxy object to access a WCF channel. To access any of the service methods, the call is wrapped in a try-catch to ensure well defined behavior.
However, once the channel is nonfunctional for any reason, I would like to reopen it. What is the proper way to do that? I see two questions:
1. When to check
- right before the try/catch in the access methods
- via the Faulted, Aborted, etc events of the channel
2. How to perform the reopen
This troubled me quite a bit. If i understand the situation correctly, I have to handle every possible state separately. Also, I possibly have to avoid threading issues such as opening the channel twice if two method calls were received at the same time (only applies to option A of the previous point).
I recall there being a lot of things to consider when reopening a channel. It is required to differentiate between Faulted and Closed (and Closing), order of operations does matter, and certain operations invalidate the object (?).
And as if that were not enough trouble, the MSDN apparently provides wrong example code (missing cases, sloppily dealing with edge conditions etc.) so I can't rely on that at all.