Exception with WCF

What is the best way to resolve an exception from a WCF service? How can you throw an exception from WCF service?

0


source to share


3 answers


Using faults.

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



or

Jean-Paul Smits blogg

+2


source


FaultContract is the way to go. The MSDN link given in another answer is a good place to look. It should be noted, however, that:

Resist the temptation to place Exception-derived classes in response to an error

Do not follow FaultContract<ArgumentException>



Rather create FaultContract<NameCanNotHaveDigitsFault>

where NameCanNotHaveDigitsFault

is your domain specific class, not tied to a specific framework.

+2


source


You can throw FaultExceptions from the wcf service, they will be passed back to the client.

Any other type of exception will put your communication channel into a bad mode, making it unusable.

So the easiest (quickest and dirtiest) way to throw exceptions in a wcf service is to wrap / modify them in FaultExceptions.

0


source







All Articles