简体   繁体   中英

Throwing FaultException<T> from WCF service methods

I am learning WCF, and currently focusing on the Faults chapter.

As i understand, WCF handles FaultException exceptions a bit differently when thrown by a service.

As such, it seems like a good idea that all exceptions that are thrown from a service should be wrapped into a FaultException.

Design wise it seems a bit counter-intuitive for me with respect to the design that WCF seems to favor (a clean separation between the actual logic and the "service" configuration/hosting/service-like details).

Is this a good practice then? or is there any other technique that should be used?

It is common practice to set up a FaultContract on your WCF service, which defines how it is has failed, and then handle this at the client side.

http://msdn.microsoft.com/en-us/library/ms733721.aspx

http://blogs.msdn.com/b/endpoint/archive/2011/01/14/wcf-spike-faultcontract-faultexception-lt-tdetail-gt-and-validation.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM