Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increasing timeout for WCF web service in c#

Tags:

c#

wcf

I currently have an application that is calling a web service on a server for searching. We can expect a large amount of data to be returned, so a search to take longer than a minute is routine.

We've been receiving the below error message for such large volume searches:

The request channel timed out while waiting for a reply after 00:00:59.7350618. 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.

This is something that we've seen asked in multiple questions already posted on StackOverflow, unfortunately none of the available solutions have helped me fix the issue or even be able to configure the time out window.

We've both changed the app.config for the client, increased all the timeouts involved there (CloseTimeout, OpenTimeout, ReceiveTimeout, and SendTimeout) and all web.config values for the service on the server (closeTimeout, openTimeout, and SendTimeout).

None of these changes have had any effect, I still receive the minute timeout. Any idea why changes to these values would have no effect?

In the examples below, we lowered the time to keep us from having to wait for the full minute during testing.

Web.config:

<configuration>
  <system.web>
    <compilation targetFramework="4.0" />
  </system.web>
  <system.diagnostics>
    <trace autoflush="true" />
    <sources>
      <source name="System.Net">
        <listeners>
          <add name="TraceFile" />
        </listeners>
      </source>
      <source name="System.Net.Sockets">
        <listeners>
          <add name="TraceFile" />
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add name="TraceFile" type="System.Diagnostics.TextWriterTraceListener"
           initializeData="trace.log" />
    </sharedListeners>
    <switches>
      <add name="System.Net" value="Verbose" />
      <add name="System.Net.Sockets" value="Verbose" />
    </switches>
  </system.diagnostics>
  <system.serviceModel>
    <diagnostics>
      <messageLogging logMalformedMessages="false" logMessagesAtServiceLevel="false"
                      logMessagesAtTransportLevel="false" />
    </diagnostics>
    <services>
      <service behaviorConfiguration="SearchIndexServiceBehavior" name="SearchIndex.Service">
        <endpoint address="" binding="basicHttpBinding" contract="ISearchIndexServices" />
        <host>
          <timeouts closeTimeout="00:00:10" />
        </host>
      </service>
    </services>
    <bindings>
      <basicHttpBinding>
        <binding closeTimeout="00:00:10" openTimeout="00:00:15" sendTimeout="00:00:20"
                 receiveTimeout="00:00:25" maxBufferSize="2147483647" maxBufferPoolSize="2147483647"
                 maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                        maxArrayLength="2147483647" maxBytesPerRead="2147483647"
                        maxNameTableCharCount="2147483647" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="SearchIndexServiceBehavior">
          <serviceMetadata httpGetEnabled="false" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
  <system.transactions>
    <defaultSettings timeout="00:05:00" />
  </system.transactions>
</configuration>

app.config

<configuration>
  <configSections>
  </configSections>
  <startup>
  </startup>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_ISearchIndexServices" closeTimeout="00:00:10" openTimeout="00:00:15" receiveTimeout="00:10:00" sendTimeout="00:00:20" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="5242880" maxBufferPoolSize="524288" maxReceivedMessageSize="5242880" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"> 
          <readerQuotas maxDepth="32" maxStringContentLength="5242880"maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://MyServer/SearchIndexService/SearchIndexServices.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISearchIndexServices" contract="WFC.ISearchIndexServices" name="BasicHttpBinding_ISearchIndexServices" />
    </client>
  </system.serviceModel>
</configuration>
like image 403
user1183014 Avatar asked Feb 01 '12 16:02

user1183014


3 Answers

I think you are probably hitting the OperationTimeout for the client side request channel, which for some reason is not easily adjusted via the standard configuration attributes.

Try this in the client code before calling the long-running operation:

((IContextChannel)clientProxy.InnerChannel).OperationTimeout = new TimeSpan(0,30,0); // For 30 minute timeout - adjust as necessary

where clientProxy is an instance of the service-reference-generated Client class (which is derived from ClientBase<ISearchIndexService>).

like image 83
Chris Dickson Avatar answered Oct 12 '22 02:10

Chris Dickson


You can try this

 SeriveClient client=new ServiceClient();
    var time = new TimeSpan(0, 3, 0);
    client.Endpoint.Binding.CloseTimeout = time;
                client.Endpoint.Binding.OpenTimeout = time;
                client.Endpoint.Binding.ReceiveTimeout = time;
                client.Endpoint.Binding.SendTimeout = time;
like image 28
Dinesh Kumar Avatar answered Oct 12 '22 03:10

Dinesh Kumar


This Service Model example shows the binding element timeout properties that needed to be set in the client web.config.

Notice that all of the timeout properties are set to 10 minutes. This example uses a binding configuration element to set the "maxItemsInObjectGraph" property. Usually if you need to turn the timeout up, that means you are probably transferring large amounts of data. Notice also that the sizes of the data to be transferrred are all set to handle up to 2 gigabytes.

<?xml version="1.0" encoding="UTF-8"?>
<system.serviceModel>
   <bindings>
      <basicHttpBinding>
         <binding name="BasicHttpBinding_ISearchIndexServices" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10: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="None">
               <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
               <message clientCredentialType="UserName" algorithmSuite="Default" />
            </security>
         </binding>
      </basicHttpBinding>
   </bindings>
   <client>
      <endpoint address="http://MyServer/SearchIndexService/SearchIndexServices.svc" behaviorConfiguration="SearchIndexServicesBehavior" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISearchIndexServices" contract="WFC.ISearchIndexServices" name="BasicHttpBinding_ISearchIndexServices" />
   </client>
   <behaviors>
      <endpointBehaviors>
         <behavior name="SearchIndexServicesBehavior">
            <dataContractSerializer maxItemsInObjectGraph="2147483647" />
         </behavior>
      </endpointBehaviors>
   </behaviors>
</system.serviceModel>
like image 5
BuzzWilder Avatar answered Oct 12 '22 01:10

BuzzWilder