【问题标题】:OpenRiaServices async methodsOpenRiaServices 异步方法
【发布时间】:2025-11-24 10:05:02
【问题描述】:

我仍在使用 OpenRiaServices,并更新到版本 5.0.0-preview0003。

我尝试添加一个异步方法:

[Invoke]
[RequiresAuthentication]
public async Task<string> GetTestAsync()
{
   return await Task.FromResult("TEST");
}

但是当我调用它时,该方法永远不会返回:

var test = DomainContext.GetTestAsync(CancellationToken.None).Result;

我看到生成的代码中没有“等待”:

/// <summary>
/// Asynchronously invokes the 'GetTest' method of the DomainService.
/// </summary>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
/// <returns>An operation instance that can be used to manage the asynchronous request.</returns>
[DebuggerStepThrough()]
public System.Threading.Tasks.Task<InvokeResult<string>> GetTestAsync(CancellationToken cancellationToken = default(CancellationToken))
{
    this.ValidateMethod("GetTest", null);
    return this.InvokeOperationAsync<string>("GetTest", null, true, cancellationToken);
}

我试图调试它,但我不知道问题出在哪里......

知道为什么吗?

【问题讨论】:

标签: wcf-ria-services


【解决方案1】:

[在 OpenRiaServices Github 上](https://github.com/OpenRIAServices/OpenRiaServices/issues/246) 已经回答了这个问题

问题是由于调用Task.Result 而不是await 导致的死锁

【讨论】:

    最近更新 更多