I am currently doing some research on how to handle exceptions and let the client know in a winforms app which calls a WCF service (Self-hosted in a windows service). What is the best way for this? A couple of questions:
1) If I let an exception propagate, it’ll come up on the client side.
2) What’s the best way to catch the exception on the client side? Is it:
catch (FaultException<T> fault) { }
(Empty catch block just for demo purposes). Or is there another way?
You will need to put each of your calls in a try{}catch{} block since that is where it will be propagated from on the client side, possibly encompassing some of the possible exception handing in some sort of proxy to hide the WCF specific handling.
Using exception shielding you can also specify custom FaultExceptions and decorate the method with attributes to allow that exception to be sent down to the client. That way you can be a little more intelligent when the exception arises.
e.g.
Id reccomend reading http://blogs.msdn.com/b/pedram/archive/2008/01/25/wcf-error-handling-and-some-best-practices.aspx as it has a few good tips/