在 WCF 代理上调用异步方法时超时

Timeout when calling async method on a WCF proxy

我正在尝试从 WPF 客户端测试我构建的小型 WCF 服务,当我在服务代理上调用异步方法时得到 TimeoutException

async void ExecuteProcessNowCommand()
{
    try
    {
        await _proxy.ProcessAsync(true);
    }
    catch (FaultException<FaultExceptionData> fix)
    {
        MessageBoxFacility.ProcessingError(fix.Detail.ExceptionType + ": " + fix.Detail.Message, fix.Detail.StackTrace);
    }
}

此代码来自我的视图模型,用于响应按钮的命令。

异常未处理,并且未通过 FaultException。这里实际上超时的是什么?我假设 await 不会阻塞并超时,所以我怀疑它在其他地方,但 await 可能会导致超时吗?异常消息是:

An exception of type 'System.TimeoutException' occurred in mscorlib.dll but was not handled in user code

Additional information: The HTTP request to 'http://localhost:8089/TestService/SchedulerService/' has exceeded the allotted timeout of 00:01:00. The time allotted to this operation may have been a portion of a longer timeout.

WCF 托管在 Windows 服务中,调用该方法时该服务为 运行。我应该从哪里开始寻找诊断方法?

WCF has a timeout on many operations。操作是否为 async 无关紧要。默认情况下,大多数 WCF 超时为一分钟,这符合您的例外情况。

可用超时为:

  1. OpenTimeout
  2. 关闭超时
  3. 发送超时
  4. 接收超时

在您的情况下,相关超时可能是 SendTimeout,因为操作可能超过一分钟。

这个异常 System.TimeoutException 不会在 FaultException 下,因为它是客户端异常,它不是来自服务器。

如果你想处理这个异常你需要添加一个合适的catch子句。要消除此异常,您需要确保操作不超过分配的时间或将超时配置增加到更合理的值。