user1183014
user1183014

Reputation: 171

Increasing timeout for WCF web service in c#

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>

Upvotes: 17

Views: 47996

Answers (5)

Keenan Stewart
Keenan Stewart

Reputation: 634

Timeouts are a pain in debugging. Who can debug in under a minute! I used Junior M/BuzzWilder from above and added the following to the service call in the app.config:

            <binding name="WSHttpBinding_bindingname"
                     openTimeout="01:00:00"
                     closeTimeout="01:00:00"
                     receiveTimeout="01:00:00"
                     sendTimeout="01:00:00"
                     >

Good bye service time outs. :)

Upvotes: 1

BuzzWilder
BuzzWilder

Reputation: 61

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>

Upvotes: 6

Dinesh Kumar
Dinesh Kumar

Reputation: 169

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;

Upvotes: 6

Chris Dickson
Chris Dickson

Reputation: 12135

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>).

Upvotes: 24

Richard Blewett
Richard Blewett

Reputation: 6109

The timeout is the send timeout on the client. This is how long the client is prepared to wait for a response and so has to be set on the client rather than the service

Upvotes: 0

Related Questions