Question

Strangely I can't find anything on google for this. When doing regular exception stuff you'd create a MyCustomException : Exception and I assumed the same applied to ExceptionFaults.

When someone calls my service with an invalid api key, I wanted to throw an InvalidApiKeyExceptionFault. I can't seem to find an example online of how to set this up and have the client be able to catch it (presumably an attribute somewhere to include it into the WSDL).

Any suggestions where to look, or am I trying something that's not possible?

Was it helpful?

Solution

You should use FaultException<TDetail> and put your specific information in the serializable TDetail type.

Your service contract should have a fault contract specifying the TDetail type.

This technique enables you to communicate error information in an interoperable way, including to clients that know nothing about .NET exceptions.

If for some reason you don't want to use fault contracts, you could consider using the non-generic FaultException, and communicate additional information about the error in the fault reason and/or fault code / subcode.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top