开发者

WCF Server Exception Handling in UI

开发者 https://www.devze.com 2022-12-19 19:32 出处:网络
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 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 besi开发者_JAVA技巧de 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消