我有一个有时必须返回故障的 WCF 服务。由于某种原因,对我的服务的调用开始超时并出现以下错误:“请求通道在 00:00:59.8906201 之后等待回复时超时。增加传递给请求的调用的超时值或增加 SendTimeout绑定上的值。分配给此操作的时间可能是较长超时的一部分。
检查问题后,出现了一个模式:当服务返回故障 10 次时,超时开始。所以我创建了一个通过以下方式实现的测试服务:
public string GetData(int value)
{
throw new FaultException("A testerror occured");
}
和一个测试客户端:
protected void RunTestGetData()
{
using (TestServiceReference.Service1Client client
= new WSPerformanceTester.TestServiceReference.Service1Client())
{
try
{
client.GetData(1);
client.Close();
outputWriter.WriteLine(string.Format("Call run in thread {0}: GetData()", Thread.CurrentThread.ManagedThreadId));
outputWriter.Flush();
}
catch (Exception e)
{
client.Abort();
client.Close();
outputWriter.WriteLine(string.Format("Error occured in thread {0}: GetData(): {1}", Thread.CurrentThread.ManagedThreadId, e.Message));
outputWriter.Flush();
}
}
}
这只发生在服务返回 FaultException 时。如果我抛出一个正常的异常,服务能够在第 10 次调用后继续运行。显然,我想很好地包装我的异常,所以仅仅抛出正常的异常并不是一个真正的选择。
为什么我会遇到这些超时异常?提前感谢您的帮助..