Exception handling in RIA Service

后端 未结 3 1361
长情又很酷
长情又很酷 2021-02-19 07:20

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 servi

相关标签:
3条回答
  • 2021-02-19 07:44

    I've read about using WCF faults in Silverlight, but haven't yet tried it with WCF RIA.

    http://mark.mymonster.nl/2011/02/10/make-use-of-wcf-faultcontracts-in-silverlight-clients/

    0 讨论(0)
  • 2021-02-19 07:48

    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.

    0 讨论(0)
  • 2021-02-19 08:05

    Code example:

    [EnableClientAccess()]
    public class YourDomainService : DomainService
    {
        protected override void OnError(DomainServiceErrorInfo errorInfo)
        {
                base.OnError(errorInfo);
    
                customErrorHandler(errorInfo.Error);
        }
    
        private void customErrorHandler(Exception ex)
        {
                DomainServiceContext sc = this.ServiceContext;
    
                //Write here your custom logic handling exceptions
        }
    }
    
    0 讨论(0)
提交回复
热议问题