我在一個循環中重複調用WCF服務方法(每次迭代時使用不同的參數)並且它在大約40分鐘後導致超時。我使用相同的代理對象,只有在循環完成後才關閉它。我怎樣才能避免這個超時錯誤?是否需要爲每個呼叫實例化一個新的代理? (實際上,我在這裏調用SQL服務器報告服務器webservice並傳遞不同的參數來生成不同的報告,並且我沒有使用每個迭代的新代理,因爲它們可能會減慢報告的生成速度)。這裏的客戶端也是一個WCF服務,它託管在一個Windows服務中。在一個循環(使用相同的代理對象)中多次調用WCF服務方法導致超時
(這只是用於說明的例子,而不是發生故障的實際的代碼)
using(var proxy=new serviceclient())
{
for(var i=0;i<50;i++)
{
proxy.methodName(i);
}
}
該錯誤消息是這樣的
System.TimeoutException:請求 信道定時等待00:01:00後回覆 。將傳遞給調用的超時值 增加到 請求或增加綁定上的SendTimeout值 值。分配給此操作的時間 可能有 是較長超時的一部分。 ---> System.TimeoutException:到 'http://localhost/ReportServer/ReportExecution2005.asmx' 的HTTP請求已超出分配的超時時間 00:01:00。分配給此 操作的時間可能是更長超時的一部分。 ---> System.Net.WebException:操作 超時
這裏是客戶端WCF配置
<bindings>
<basicHttpBinding>
<binding name="ReportExecutionServiceSoap" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647"
maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost/ReportServer/ReportExecution2005.asmx"
binding="basicHttpBinding" bindingConfiguration="ReportExecutionServiceSoap"
contract="ReportExecutionServiceReference.ReportExecutionServiceSoap"
name="ReportExecutionServiceSoap" />
</client>
(只關係到報告服務,而不是整個WCF配置的一部分)
這裏每個方法調用都是同步的,所以客戶端會等待直到生成報告,然後再發出請求另一個報告。現在我正試圖爲每個調用實例化並關閉代理,並查看它是否有效。謝謝回覆 – RKP 2011-01-09 13:24:23