Multi Language / Multicultural Exception Handling In WCF Using FaultReason

Jan 10, 2011

1 min read

C#

Architect

WCF

Author picture

by jebarson

Contributor

13k Views

It was during the Virtual Tech Days when I was presenting the "Exception Handling In WCF" session, one attendee wanted on how to use the fault reason to have multilingual / multicultural exceptions being handled and shown without any extra code. And so I promised him that I would post an article on the same and here it is now.

To start with, FaultReason accepts a list of FaultReasonText which can be basically said to have exception messages for multiple cultures. The same can be added as below:

CS
List reasonText = 

Now all I have to do is to set the culture in the UI to the current thread and call the method to get the current culture and bind the property as below:

CS
ex.Reason.GetMatchingTranslation().Text;

Where ex will be the FaultException. Always remember that this works only with SOAP 1.2 and therefore you will need to write a custom binding as mentioned in this sample.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)