views:

42

answers:

2

I would like to be able to catch exception from the server and display an error beside a field that related to the error.

I have a NTier client server application that uses WCF services and DTOs to pass data from the server to the client and back. I would be validating a domain object on the server and if it had error I would want to throw an exception that would be caught on the client and display a message beside the relevant field.

Has anyone done something similar before? This would seem like a pretty common scenario yet I haven't come across any solutions to it.

Thanks in advance.

+1  A: 

An article you might find of use: Here

thedugas
+3  A: 

First of all, you cannot catch exceptions from the server on the client. What will happen is that the server will return a SOAP Fault, which a WCF client will translate into an exception of type FaultException<T>, where T is the fault type. A WCF service can return such a fault by throwing an exception of type FaultException<T>.

You can define the fault type to include information on the field that had the problem, and a message explaining the problem. These can be processed in the client UI to highlight the form field with the problem.

John Saunders