RIA服务中的异常处理

发布于 2024-11-03 04:48:47 字数 492 浏览 3 评论 0原文

如您所知,建议使用带有标准 WCF 服务的FaultException 来处理异常,以隐藏异常详细信息。没关系,但我在使用 WCF Ria 服务时遇到问题。我想从域服务抛出异常,客户端将处理该异常。我想避免泄露异常的敏感信息,例如堆栈跟踪、方法名称等。如果是标准 WCF 服务,我会使用FaultException 异常,但在 Ria 服务中,它不起作用。无论我从域服务抛出哪种异常,客户端总是会收到 DomainOperationException。有什么方法可以从域服务向 silverlight 客户端抛出FaultException(不透露实际的异常详细信息)?例如,我有一个登录窗口。当用户点击登录按钮时,应该有几个验证失败,例如:

  • 无效的用户名或密码
  • 用户帐户被锁定
  • 帐户未激活

我希望为每个可能发生的错误提供错误类型。客户端应该检查出了什么问题并相应地显示错误消息。我禁用了 customErrors 但没有帮助。任何帮助将不胜感激。 谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

眼藏柔 2024-11-10 04:48:47

这是科林·布莱尔对我的问题的回答

DomainService 有一个可重写的
名为 OnError 的方法。每当有
是一个例外
DomainService 本身(不在
WCF代码)异常将被传递
在重新抛出之前到 OnError
发送回客户端。如果你
替换中的异常
DomainServiceErrorInfo 传递到
OnError 方法与您自己的异常
那么你的例外将是一个
被发送回客户端。如果
您将 DomainException 用于您的
例外那么你将能够
传入一个 ErrorCode 整数,您可以
可以使用客户端来确定
实际错误。

它回答了我的问题和需求。谢谢科林。

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.

对风讲故事 2024-11-10 04:48:47

我读过有关在 Silverlight 中使用 WCF 错误的信息,但尚未尝试使用 WCF RIA。

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

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/

墨小沫ゞ 2024-11-10 04:48:47

代码示例:

[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
    }
}

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
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文