在RIA服务异常处理 [英] Exception handling in RIA Service

查看:153
本文介绍了在RIA服务异常处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如你所知,它的使用recomended用的FaultException标准WCF服务来隐藏异常细节处理异常。这很好,但我有与WCF RIA服务的问题。我想扔从域名服务异常,客户端将处理该异常。我想,以避免泄露异常的敏感信息,如堆栈跟踪,方法名等,如果它是标准的WCF服务,我会使用的FaultException异常,但在利雅服务,它不工作。不管我从域名服务抛出什么样的异常,客户端总是得到DomainOperationException。有什么办法,我可以抛出的FaultException到Silverlight客户端从域名服务(不透露实际的异常详细信息)?例如,我有一个登录窗口。当用户击的登录按钮,应该有几个验证失败,如:

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

我想有故障类型可能occure每个错误。客户应检查哪些相应出了错,并且显示错误消息。我禁用的customErrors但它并没有帮助。任何帮助,将不胜感激。
谢谢

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

推荐答案

下面就是科林·布莱尔回答我的问题的这里

Here's what Colin Blair answered to my question here

的DomainService有一个名为的OnError可重写
法。每当有

的DomainService本身(而不是内
WCF代码)的异常将被传递
到ONERROR之前它被重新抛出是
发送内的异常返回给客户端。如果你
更换例外在
DomainServiceErrorInfo传递到与自己的异常

onError方法那么你的异常将是被发送回一个
客户。如果
使用DomainException您
例外,那么你就可以
传递一个错误码整数你
可以使用客户端来确定
实际的错误

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.

这篇关于在RIA服务异常处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆