Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Dec 28, 2012 05:33 AM by JasonMing
Dec 14, 2012 01:32 AM|LINK
I wanna implements the unified exception handlings in my wcf service.
I've found some solutions from Google, but all are talking about using FaultException and IErrorHandler to return a "Fault" message, not a "Result" message.
Due to my bussiness logic, I have to convert the exception to the result code.
If there is any solution to implement this ?
Dec 14, 2012 07:12 AM|LINK
Please see this
Dec 14, 2012 07:35 PM|LINK
You can send the result code depends on business logic -
catch (FaultException<YourService.BizLayerExceptionFault> ex)
loTraceManager.AddInformation("Error Message from YourService.BizLayerExceptionFault : " + ex.Detail.Message);
throw new WebFaultException<ServiceFault>(new ServiceFault("RESERVATION_EXCEPTION",
Dec 17, 2012 12:31 AM|LINK
Thanks for replying, but this is not my really want.
Throw a web fault will cause server response a non-200 status code, and response a non-soap datagram.
What I want is:
bussiness error, but should not belong to the "Fault" situation:
<Message>The error message</Message>
The above result is my want to do with. I want to handle the exception which is part of bussiness logic result, but not throw directly with the FaultException and returning the <Fault> node to the client.
I know it's possible that try-catch (or some exception handling block) in every operation, but it is a really annoying way to do that.
So, is there any way to handle the exception out of the operation without returning the <Fault> node (like the post-xxx interceptor) ?
Dec 18, 2012 04:58 AM|LINK
According to your description, you can use FaultContracts to return custom error messages.
#How to: Return Custom Error Messages Using FaultContracts
Dec 18, 2012 12:55 PM|LINK
Check this article -
You can create a data contract and have fault contract as per your businee logic.
Dec 23, 2012 06:49 AM|LINK
Hi, thanks for replying,
But this is not my expected, you know, in some bussiness logic, some situation could not be classified as a really fault, it is a normal situation of the bussiness.
Because "fault" message in soap will raise and exception, but some platform has no enough support to the exception, like objective-c.
If I can handle these exceptions in global scope and convert to the status code (not a fault message), it will be more convenient for many non-c# clients.
Dec 27, 2012 06:04 PM|LINK
What you can do instead it say you have one class object or xml that you are responding back.
In catch block you can feel this class object or xml with appropriate message related to error as per your business logic and send it back to customer.
Dec 28, 2012 05:33 AM|LINK
Thanks replying again,
Anyway, I know that it has no way to reach my expect, I've to use try-catch in every exposed service. There is no convenient ways.