Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception handling in RIA Service

As you know, it's recomended handle exceptions using FaultException with standard WCF service to hide exception details. That's fine but i'm having problem with WCF Ria service. I want to throw an exception from domain service and the client will handle that exception. I want to avoid disclosing exception's sensitive information such as stack trace, method names etc. If it were standard WCF service, I'd use FaultException exception, but in Ria service, it's not working. No matter what kind of Exception I throw from domain service, the client always gets DomainOperationException. Is there any way I can throw a FaultException to the silverlight client from domain service (to not disclose actual exception details)? For example, I have a login window. When the user hit's login button, there should be several validation failures, such as:

  • Invalid username or password
  • User account is locked
  • The account is not activated
  • etc

I want to have fault types for each error that may occure. The client should check what went wrong and display error message accordingly. I disabled customErrors but it didn't help. Any help would be appreciated. Thanks

like image 845
Davita Avatar asked Apr 23 '11 19:04

Davita


1 Answers

Here's what Colin Blair answered to my question here

The DomainService has an overridable method named OnError. Whenever there is an exception within the DomainService itself (not within the WCF code) the exception will be passed to OnError before it is rethrown to be sent back to the client. If you replace the exception in the DomainServiceErrorInfo passed into the OnError method with your own exception then your exception will be the one that gets sent back to the client. If you use the DomainException for your exception then you will be able to pass in an ErrorCode integer which you can use client side to determine the actual error.

It answers my question and needs. Thanks Colin.

like image 136
Davita Avatar answered Oct 03 '22 07:10

Davita