I have a WCF service deployed on two or more remote machines and there is a desktop based application that is used by the client to access any wcf service.
The WCF service is connected to SQL server 2005 to read and write data.
This is an intranet scenario in which the client should be on same domain.
Now there can be scenarios where the wcf service throws exceptions:
- Invalid URL
- WCF service is down
- SQL server 2005 is not running
- Client is not on the same domain
- Authentication fails
- Authorization fails
and many other exceptions.
For every exception I have to perform some action or update a status bar, depending on the exception. For example if authorization fails I have to prompt the user to re-enter their credentials.
Please suggest the best design approach to handle this.
You can definitely catch and handle all exceptions that happen on your service class and turn them into a FaultException or FaultException exception.
That way, you won’t "fault" (or tear down) the communications channel between your client and server.
Even better approach would be to implement the
IErrorHandlerinterface on your service class that provides a way to globally catch all exceptions as they happen and provide a FaultException instead, that’s SOAP compliant.You can even turn your
IErrorHandlerinto a configurable behavior that can be turned on or off in config.See these articles and blog posts for more details: