multiple calls to WCF service method in a loop (using the same proxy object) causing timeout
I am calling a WCF service method repeatedly in a loop (with different params on each iteration) and it is causing timeout after around 40 mins. I am using the same proxy object and closing it only once the loop is completed like this. how can I avoid this timeout error? do I need to instantiate a new proxy for each call. (actually I am calling a SQL server reporting server webservice here and passing different params to generate different reports and I am not using a new proxy for each iteration thinking that could slow down generation of reports). here is the client is also a WCF service and it is hosted in a windows service.
(this is just an example for illustration, not the actual code that is failing)
using(var proxy=new serviceclient())
{
for(var i=0;i<50;i++)
{
proxy.methodName(i);
}
}
The error message is something like this
System.TimeoutException: The request channel timed out while waiting for a reply after 00:01:00. Increase the timeout value passed to the call to Request or increase the SendTimeout value on the Binding. The time allotted to this operation may have been a portion of a longer timeout. ---> System.TimeoutException: The HTTP request to 'http://localhost/ReportServer/ReportExecution2005.asmx' has exceeded the allotted timeout of 00:01:00. The time allotted to this operation may have been a portion of a longer timeout. ---> System.Net.WebException: The operation has timed out
here is the client WCF config (only part that is related to the reporting services, not the entire WCF config)
<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"
开发者_Python百科 name="ReportExecutionServiceSoap" />
</client>
this issue is resolved now. one of the reports (generated by making a call to the report server ASMX webservice) was taking longer than usual and causing the timeout, it was NOT due to the number of calls in the loop (each webservice call is synchronous and not queued up). To resolve this, I used the standard ASP.NET webservice API instead of WCF to call the report execution webservice and set the timeout to infinite like this
var webServiceProxy = new ReportExecutionServiceReference.ReportExecutionService()
{
Url = ConfigurationManager.AppSettings["ReportExecutionServiceUrl"],
Credentials = System.Net.CredentialCache.DefaultCredentials
};
webServiceProxy.Timeout = Timeout.Infinite;
the timeout could have been set to a bigger value instead of infinite as well. this webservice is called in a loop for each report and it takes about two hours to generate all the user selected reports in one go. client is a WCF service and hosted in a windows service instead of IIS to avoid a timeout on the client. thanks for all the replies.
If you are doing asynchronous calls from the client and the server is not a "webfarm" all the calls will be qued on the server. And that could make calls timeout. It doesn't really say fron your code.
Let say that you do are going through a list with 10 items, each response takes 10 seconds to process on the server. Since you are using the same proxy all calls will be quite quick to dispatch from client code. But it will take around 100 seconds to return all answers ( note that i dont take into consideration that you have network latency, object serilization etc etc) That means that all calls after nr 6 will timeout.
If the server would have more threads available to process data this could ve avoided, but the problem could popup somewhere else. You should be able to try the same call again, since a timeout could accour for any other reason as well, network problem, temporary server overload etc etc.
I would sugest making some sort of quing system that dispatches all the server calls so that you could make the same call again. How that would be implemented depends on your scenario: Do they need to be sent in a specific order? Do you need to know when the last call has returned? etc.
This simply means your server can't deal with the load, or is taking too long for some other reason. Ask the server why it's taking too long; don't be surprised when the client times out.
Dim ws As WCFService.ServiceClient = New WCFService.ServiceClient
ws.Endpoint.Binding.SendTimeout() = TimeSpan.FromSeconds(2)
精彩评论