0

I have a WCF service and there is a CustomFaultException class inheriting from FaultException.

I have set the below code:

<serviceDebug includeExceptionDetailInFaults="False"/>

But it always returns the Exception with full stack trace details.

How to configure or implement a WCF Service so that only returns certain types of Exceptions e.g. CustomFaultException?

Thanks

The Light
  • 26,341
  • 62
  • 176
  • 258
  • As far as i know, WCF does not include exception details by default, so you must have some code or configuration which activates sending of exception details to the client. – Jan Nov 13 '12 at 16:02

1 Answers1

1

Add the following attribute to your Service Operation:

[FaultContract(typeof(CustomFaultException))]

Within your catch, add the following:

throw new CustomFaultException("Custom Fault Message");

This will prevent the full stack trace exception details from being sent to the client.

dhirschl
  • 2,088
  • 13
  • 18
  • I should point out that using exception classes in fault contracts is *not* best practice. However, it correctly answers the question, so +1. – Christian Hayter Nov 13 '12 at 17:35