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.
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) ?
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.
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.
JasonMing
0 Points
5 Posts
How can I handle the exceptions without returning a "Fault" message in WCF ?
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 ?
vijayaakumar
Member
104 Points
24 Posts
Re: How can I handle the exceptions without returning a "Fault" message in WCF ?
Dec 14, 2012 07:12 AM|LINK
Hi,
Please see this
http://stackoverflow.com/questions/81306/wcf-faults-exceptions-versus-messages
Thanks
kushalrdalal
Contributor
7130 Points
1271 Posts
Re: How can I handle the exceptions without returning a "Fault" message in WCF ?
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", string.Format(ex.Detail.Message)), HttpStatusCode.BadRequest); }My Blog
LinkedIn Profile
JasonMing
0 Points
5 Posts
Re: How can I handle the exceptions without returning a "Fault" message in WCF ?
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:
normal situation:
bussiness error, but should not belong to the "Fault" situation:
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) ?
Haixia Xie -...
Contributor
3023 Points
294 Posts
Microsoft
Re: How can I handle the exceptions without returning a "Fault" message in WCF ?
Dec 18, 2012 04:58 AM|LINK
Hi,
According to your description, you can use FaultContracts to return custom error messages.
#How to: Return Custom Error Messages Using FaultContracts
http://msdn.microsoft.com/en-us/library/ff650547.aspx
Best Regards.
Feedback to us
Develop and promote your apps in Windows Store
kushalrdalal
Contributor
7130 Points
1271 Posts
Re: How can I handle the exceptions without returning a "Fault" message in WCF ?
Dec 18, 2012 12:55 PM|LINK
Check this article -
http://msdn.microsoft.com/en-us/library/ms733841.aspx
You can create a data contract and have fault contract as per your businee logic.
My Blog
LinkedIn Profile
JasonMing
0 Points
5 Posts
Re: How can I handle the exceptions without returning a "Fault" message in WCF ?
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.
kushalrdalal
Contributor
7130 Points
1271 Posts
Re: How can I handle the exceptions without returning a "Fault" message in WCF ?
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.
My Blog
LinkedIn Profile
JasonMing
0 Points
5 Posts
Re: How can I handle the exceptions without returning a "Fault" message in WCF ?
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.