我正在尝试从 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);
}
}
此代码来 self 的 View 模型,响应按钮的命令。
异常未处理,并且不是通过 FaultException
来的。这里实际上什么是超时?我假设等待不会阻塞并超时,所以我怀疑它在其他地方,但是 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 。操作是否异步并不重要。大多数 WCF 超时默认为一分钟,这符合您的异常(exception)情况。
可用的超时是:
- 打开超时
- 关闭超时
- 发送超时
- 接收超时
在您的情况下,相关超时可能是 SendTimeout,因为操作可能超过一分钟。
此异常 System.TimeoutException
不会位于 FaultException
下,因为它是客户端异常,不是来自服务器。
如果你想处理这个异常,你需要添加一个适当的catch子句。要消除此异常,您需要确保操作不超过分配的时间或将超时配置增加到更合理的值。
关于.net - 在 WCF 代理上调用异步方法时超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29027585/