Handling exceptions WPF Application with a WCF Service?

Microsoft recommends implementing IErrorHandler for WCF exceptions.

Up vote 3 down vote favorite 1 share g+ share fb share tw.

I have a WCF Service that talks to the DB. All the operations go through the service. What is the best way to return an exception to the client(in this case WPF application).

Lets say I have GetCustomer in the service which returns a list of customers. But this had an exception. How should I return this exception to the client?

.net wcf . Net-4.0 wcf-client link|improve this question asked Dec 19 '11 at 19:55katie771409 38% accept rate.

Microsoft recommends implementing IErrorHandler for WCF exceptions To explicitly control the behavior of the application when an exception is thrown, implement the IErrorHandler interface and add it to the ErrorHandlers property. IErrorHandler enables you to explicitly control the SOAP fault generated, decide whether to send it back to the client, and perform associated tasks, such as logging. Error handlers are called in the order in which they were added to the ErrorHandlers property.

Implement the ProvideFault method to control the fault message that is returned to the client. Implement the HandleError method to ensure error-related behaviors, including error logging, assuring a fail fast, shutting down the application, and so on. Here is better sample than MSDN IMyService proxy = ...; //Get proxy from somewhere try { proxy.MyMethod(); } catch (CommunicationException) { ... } catch (TimeoutException) { ... } catch (FaultException myFault) { MyApplicationFault detail = myFault.

Detail; //Do something with the actual fault } catch (FaultException otherFault) { ... }.

– VoodooChild Dec 20 '11 at 14:12 you do not return exception from service rather throw it from service throw new FaultException(fault); and client will catch with above code. – Surjit Samra Dec 20 '11 at 17:15.

One way to do this is to have information about any potential exceptions be part of your service contract. So, in your example, GetCustomer returns your list of customers. But it also returns a, potentially empty, set of data about any exceptions that occurred.

This is a good idea because not every consumer of your service is going to be a . NET application, to depend on sending . NET errors is not wise.

1: please indicate why this would be a good idea. – John Saunders Dec 20 '11 at 0:15.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions