In WCF service I would like to handle errors and exception using custom fault.
I need to be able in case of the error return
CustomFault with Description and Error code
How can I implement it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
First you need to create a DataContract class for your custom fault. It sounds like at a minimum in your case, this class will have an Error Code property and a Description property. Next, in your Service Contract, you’ll need to decorate any service operations that can raise this fault with the FaultContract attribute. For example:
Finally, in your service implementation, you’ll need to throw the custom fault as a FaultExcepton. For example: