C# – How to increase the web service timeout in a Windows Service application

ctimeoutwcfwindows-services

I am working on a web application that uses an asmx web service to import data in IIS7. We have a Windows Service pick up a file to import and send it thru the web service. I am getting the following error during large imports after 1 minute:

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

I have seen plenty of posts where the suggestion is to not have a web service call that runs that long. I agree in principle, but this is a low traffic, internal web site. Until proven otherwise, I believe the amount of work to re-architect the other portions of the system will be longer than updating the timeout.

So far we have tried updating the basicHttpBinding properties in the web.config, specifically the openTimeout, receiveTimeout, sendTimeout and closeTimeout properties. There was no change to the behavior.

We also tried setting these properties in the code that makes the call to the web service after the object is constructed. Still no luck.

I looked thru the IIS settings and do not see any timeout value that is currently set to 60 seconds. We also tried bumping up the executionTimeout in the web.config to no effect.

What configuration value am I missing? Are there any other ways to modify a timeout?

Update:

As requested, here are the configs:

App.config

<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="ImportServiceSoap" closeTimeout="00:02:00" openTimeout="00:02:00"
                    receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false"
                    bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="1265536" maxBufferPoolSize="12524288" maxReceivedMessageSize="1265536"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                    useDefaultWebProxy="true">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" 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://mysite.com/Importservice.asmx"
                binding="basicHttpBinding" bindingConfiguration="ImportServiceSoap"
                contract="ImportService.ImportServiceSoap" name="ImportServiceSoap" />
        </client>
    </system.serviceModel>
</configuration>

Web.config (abridged, connectionstrings removed):

<configuration>
  <appSettings>
    <system.web>
      <roleManager enabled="false" cacheRolesInCookie="false" defaultProvider="AspNetSqlRoleProvider" />
      <siteMap defaultProvider="MenuElementsProvider">
      </siteMap>
      <compilation debug="false" targetFramework="4.0">
      </compilation>
      <customErrors mode="RemoteOnly" defaultRedirect="Shared/Internal_Server_Error.html">
        <error statusCode="404" redirect="Shared/Internal_Server_Error.html" />
        <error statusCode="500" redirect="Shared/Internal_Server_Error.html" />
      </customErrors>
      <authentication mode="Windows" />
      <identity impersonate="true" />
      <authorization>
        <allow users="*" />
      </authorization>
      <trace enabled="false" requestLimit="10" pageOutput="false" traceMode="SortByTime" localOnly="true" />
      <sessionState mode="InProc" stateConnectionString="tcpip=127.1.0.1" cookieless="false" timeout="30" />
      <globalization fileEncoding="utf-8" requestEncoding="utf-8" responseEncoding="utf-8" culture="en-US" uiCulture="en-US" />
      <httpRuntime maxRequestLength="102400" requestValidationMode="2.0" executionTimeout="14400" />
    </system.web>
    <location path="DefaultWsdlHelpGenerator.aspx">
      <system.web>
        <pages styleSheetTheme="" />
        <httpRuntime maxRequestLength="1048576" executionTimeout="3600" />
      </system.web>
    </location>
    <system.webServer>
      <validation validateIntegratedModeConfiguration="false" />
    </system.webServer>
  </appSettings>
</configuration>

Best Answer

Are you updating the binding timeouts in code or just in the client's app.config? I have seen changing the app.config settings get ignored from orignal creation of the client-side webservice - so the old settings stay even though the app.config has changed. MDV

Related Topic