我有下面這段代碼寫的WCF客戶端:爲什麼WCF客戶端超時忽略
MyClient myClient = new MyClient();
string id = Guid.NewGuid();
string result = myClient.Foo(id);
Console.WriteLine(result);
這工作,但我想加一個期限的服務調用,所以異常會如果手術時間太長,會被拋出。我嘗試在綁定元素的配置文件中添加超時,如下所示:
<basicHttpBinding>
<binding
receiveTimeout="00:00:05"
sendTimeout="00:00:05"
</binding>
</basicHttpBinding>
這似乎並不可悲。
我也試過在代碼文件中,像這樣人工設置:
MyClient myClient = new MyClient();
myClient.Endpoint.Binding = new BasicHttpBinding()
{
SendTimeout = new TimeSpan(0, 0, 5),
ReceiveTimeout = new TimeSpan(0, 0, 5)
};
string id = Guid.NewGuid();
string result = myClient.Foo(id);
Console.WriteLine(result);
但同樣,它似乎並沒有工作。
我測試了一個非常慢的服務,並在20分鐘後它終於返回(正確)的答案,但超時異常不被拋出。
我試圖達到的WCF服務可能是以某種方式阻止超時?
該投射可悲地返回null。我也嘗試了一些不同的東西:myClient.InnerChannel.OperationTimeout = TimeSpan.FromSeconds(5),但也被遺憾地忽略 – Remoba