WCF RIA 调用操作异常会中断 Caliburn.Micro 协程执行?

发布于 2024-10-19 18:50:34 字数 1907 浏览 3 评论 0原文

我正在执行一系列 Caliburn.Micro IResults,方法是从 Caliburn.Micro 操作消息调用的 IEnumerable 方法返回它们。第一个 IResult 调用 WCF RIA 服务 Invoke 操作。有时此操作会失败并引发异常。这是在 IResult 中处理的,其中检查 InvokeOperation 对象是否有错误,我将错误标记为已处理,并将 IResult 的错误消息字段设置为该错误,以便我可以从客户端恢复它。

问题是,由于某种原因,这会中断协同例程的执行。我想不出任何好的理由,但是当我处于调试模式时,VS 会跳到服务器代码并调出未处理的异常帮助程序,告诉我有一个未捕获的异常(废话),并且协同例程永远不会继续执行 IEnumerable 的其他成员。

这是一些代码。

从操作消息中调用:

    public IEnumerable<IResult> Submit()
    {
        var register = new RegisterUserResult(Username, Password, Email, _userModel);
        yield return register;

        if (register.Success)
        {
            if (RegisterAsTrainer) 
                yield return new ApplyRoleToUserResult(Username, "Trainer", _userModel);
            yield return new NavigateResult(new Uri("/MainPageViewModel", UriKind.Relative));
        }
        else ErrorMessage = register.ErrorMessage;
    }

DomainService 中的代码(有时会引发异常)

    [Invoke]
    public void CreateUser(string username, string password, string email)
    {
        Membership.CreateUser(username, password, email);
    }

...其中 Membership 是 ASP.NET 类,我用它来进行成员资格管理。

调用上述服务的 IResult(为了清楚起见,省略了一些细节):

    public void Execute(ActionExecutionContext context)
    {
        ErrorMessage = null;
        Success = false;

        var ctx = new TrainingContext();
        ctx.CreateUser(_username, _password, _email, CreateUserCallback, null);
    }

    private void CreateUserCallback(InvokeOperation invokeOp)
    {
        if (invokeOp.HasError)
            invokeOp.MarkErrorAsHandled();

        Completed(this, new ResultCompletionEventArgs
            {
                Error = invokeOp.Error,WasCancelled = invokeOp.IsCanceled
            });
    }

IResult.Completed 确实 触发,但该方法的其余部分永远不会执行。我真的很抓狂,请帮助我。

I am executing a series of Caliburn.Micro IResults by yield returning them from an IEnumerable method called by a Caliburn.Micro action message. The first IResult calls a WCF RIA service Invoke operation. Sometimes this operation fails and throws an exception. This is handled in the IResult where the InvokeOperation object is checked for error, I mark the error as handled and set the IResult's error message field to the error so I can recover it from the client.

The problem is that for some reason this interrupts the co-routine executing. I can't think of any good reason why, but when I'm in debug mode VS skips to the server code and bring up the unhandled exception helper telling me there was an uncaught exception (duh), and the co-routine never continues executing the other members of the IEnumerable.

Here is some of the code.

Called from the Action Message:

    public IEnumerable<IResult> Submit()
    {
        var register = new RegisterUserResult(Username, Password, Email, _userModel);
        yield return register;

        if (register.Success)
        {
            if (RegisterAsTrainer) 
                yield return new ApplyRoleToUserResult(Username, "Trainer", _userModel);
            yield return new NavigateResult(new Uri("/MainPageViewModel", UriKind.Relative));
        }
        else ErrorMessage = register.ErrorMessage;
    }

The code in the DomainService (which sometimes throws an exception)

    [Invoke]
    public void CreateUser(string username, string password, string email)
    {
        Membership.CreateUser(username, password, email);
    }

...where Membership is the ASP.NET class, which I am using for membership management.

The IResult that calls the above service (some details elided for clarity):

    public void Execute(ActionExecutionContext context)
    {
        ErrorMessage = null;
        Success = false;

        var ctx = new TrainingContext();
        ctx.CreateUser(_username, _password, _email, CreateUserCallback, null);
    }

    private void CreateUserCallback(InvokeOperation invokeOp)
    {
        if (invokeOp.HasError)
            invokeOp.MarkErrorAsHandled();

        Completed(this, new ResultCompletionEventArgs
            {
                Error = invokeOp.Error,WasCancelled = invokeOp.IsCanceled
            });
    }

The IResult.Completed DOES fire, but the rest of the method never executes. I'm literally tearing my hair out with this, please please help me.

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

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

发布评论

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

评论(1

地狱即天堂 2024-10-26 18:50:34

呃,我明白了这一点,愚蠢的我。我正在设置 IResult Error 字段,认为稍后需要使用该信息。我不知道具有非空 Error 字段会导致协同例程执行停止(我认为只有 Canceled 字段才会这样做)。我将把它留在这里,以防其他人遇到这个问题。

Ugh I figured this out, stupid me. I was setting the IResult Error field, thinking I'd need to use that information later. I didn't know that having a non-null Error field would cause co-routine execution to halt (I thought only the Canceled field would do that). I'll leave this here in case anyone else runs into this issue.

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