WCF/WF - HTTP request has exceeded the allotted timeout

Asked By Jarrod Krige on 30-Mar-11 10:24 AM
Hello,
Please help me fix this problem:
After exactly one minute the web service times out and my changes to the config files don't seem to work. The stored procedure that is being executed requires about 5 minutes to execute. Other queries taking less than a minute execute without a problem. It is hosted on IIS7. Why is the timeout occuring?

The Service Code:

[OperationContract]
public List<ChartingObjects.SparBatteriesReport1> GetSparBatteriesReport1(DateTime dtPeriodStartDate, DateTime dtPeriodEndDate)
{
  List<ChartingObjects.SparBatteriesReport1> listReport = new List<ChartingObjects.SparBatteriesReport1>();
  SqlCommand sqlCom = new SqlCommand("sp_Report_Spar_Batteries_1", sqlCon);
  sqlCom.CommandType = System.Data.CommandType.StoredProcedure;
  sqlCom.Parameters.AddWithValue("@dtPeriodStart", dtPeriodStartDate.Date.ToString().Substring(0, 10));
  sqlCom.Parameters.AddWithValue("@dtPeriodEnd", dtPeriodEndDate.Date.ToString().Substring(0, 10));
  sqlCom.CommandTimeout = 600;
  try
  {
    sqlCon.Open();
    SqlDataReader sqlRd = sqlCom.ExecuteReader();
    while (sqlRd.Read())
    {
      ChartingObjects.SparBatteriesReport1 r = new ChartingObjects.SparBatteriesReport1()
      {
        strSubCategory = sqlRd["sctname"].ToString().Trim(),
        decValue = Convert.ToDecimal(sqlRd["value"])
      };
      listReport.Add(r);
    }
  }
  catch (SqlException)
  {
  }
  finally
  {
    sqlCon.Close();
  }
  return listReport;
}

The call to the service:

webservice.GetSparBatteriesReport1Completed += new EventHandler<GetSparBatteriesReport1CompletedEventArgs>(webservice_GetSparBatteriesReport1Completed);
         try
         {
           webservice.GetSparBatteriesReport1Async(calStart.SelectedDate.Value, calEnd.SelectedDate.Value);
         }
         catch (TimeoutException)
         {
           webservice.Abort();
         }
         catch (System.ServiceModel.CommunicationException)
         {
           webservice.Abort();
         }


The Client Config:

<xml version="1.0"?>
<configuration>
  <system.serviceModel>
  <bindings>
    <customBinding>
    <binding name="CustomBinding_Service1" receiveTimeout="09:39:00" sendTimeout="09:39:00" openTimeout="09:39:00" closeTimeout="09:39:00">
      <binaryMessageEncoding />
      <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
    </binding>
    <binding name="CustomBinding_Service" receiveTimeout="09:39:00" sendTimeout="09:39:00" openTimeout="09:39:00" closeTimeout="09:39:00">
      <binaryMessageEncoding />
      <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647"/>
    </binding>
    </customBinding>
  </bindings>
  <client>
    <endpoint address="http://localhost:51210/Services/Service.svc"
    binding="customBinding" bindingConfiguration="CustomBinding_Service1"
    contract="ServiceReference.ForeshareBusinessIntelligence.Web.Services.Service.Service"
    name="CustomBinding_Service1" />
    <endpoint address="http://10.11.0.100/Services/Service.svc" binding="customBinding"
    bindingConfiguration="CustomBinding_Service" contract="ServiceReference.Service"
    name="CustomBinding_Service" />
  </client>
  </system.serviceModel>
</configuration>


The Server Config:

<?xml version="1.0"?>
<configuration>
  <system.web>
    <authentication mode="Forms">
      <forms name="SqlAuthCookie" defaultUrl="Foreshare.aspx" loginUrl="Default.aspx" timeout="131400"/>
    </authentication>
    <membership defaultProvider="ForeshareMembership">
      <providers>
        <clear/>
        <add name="ForeshareMembership" connectionStringName="ForeshareConnection" applicationName="Foreshare" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" requiresUniqueEmail="true" passwordFormat="Hashed" maxInvalidPasswordAttempts="3" passwordAttemptWindow="10" passwordStrengthRegularExpression="" minRequiredPasswordLength="4" minRequiredNonalphanumericCharacters="1"/>
      </providers>
    </membership>
    <roleManager enabled="true" defaultProvider="ForeshareRoleManager" cookieTimeout="14400">
      <providers>
        <clear/>
        <add name="ForeshareRoleManager" type="System.Web.Security.SqlRoleProvider" connectionStringName="ForeshareConnection" applicationName="Foreshare"/>
      </providers>
    </roleManager>
    <httpRuntime executionTimeout="600" maxRequestLength="4096" useFullyQualifiedRedirectUrl="false" minFreeThreads="8" minLocalRequestFreeThreads="4" shutdownTimeout="14400"/>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
        <add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/></assemblies></compilation>
    <globalization culture="en-ZA" uiCulture="en-ZA"/>
    <trace enabled="true" localOnly="true" pageOutput="true" writeToDiagnosticsTrace="true" />
    <customErrors mode="RemoteOnly" defaultRedirect="Exception.aspx"/>
  </system.web>
  <connectionStrings>
    <add name="ForeshareConnection" connectionString="Data Source=xxx;Initial Catalog=xxx;User Id=xxx;Password=xxx; Trusted_Connection=False" providerName="System.Data.SqlClient"/>
  </connectionStrings>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <customBinding>
        <binding name="ForeshareBusinessIntelligence.Web.Services.Service.customBinding0" receiveTimeout="09:39:00" sendTimeout="09:39:00" openTimeout="09:39:00" closeTimeout="09:39:00">
          <binaryMessageEncoding maxReadPoolSize="2147483647" maxWritePoolSize="2147483647" maxSessionSize="2147483647"/>
          <httpTransport allowCookies="true" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" />
        </binding>
      </customBinding>
    </bindings>
    <services>
      <service name="ForeshareBusinessIntelligence.Web.Services.Service">
        <endpoint address="http://10.11.0.100:80/Services/Service.svc" binding="customBinding" bindingConfiguration="ForeshareBusinessIntelligence.Web.Services.Service.customBinding0" contract="ForeshareBusinessIntelligence.Web.Services.Service"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="false" />
  </system.serviceModel>
</configuration>


Why is the timeout is occuring even though I've specified a longer timeout in the config files?
Thanks.
Ravinder Jamgotre replied to Jarrod Krige on 30-Mar-11 10:53 AM
Try increasing the IIS 7 timeout

Open IIS
In Features View, double-click ASP
On the ASP page, under Services, expand Session Properties
In the Time-out field, enter a time-out value in the format hh:mm:ss. For example, enter 00:15:00 for 15 minutes
In the Actions pane, click Apply.
Jarrod Krige replied to Ravinder Jamgotre on 30-Mar-11 11:09 AM
Thanks for your response.

The Time-Out field is set at 00:20:00 but still the timeout occurs.

Any other ideas please?
Ravinder Jamgotre replied to Jarrod Krige on 30-Mar-11 11:12 AM
Amend your code for client and server timeouts. the time are 9.39.xxxx for both increase here
Jarrod Krige replied to Ravinder Jamgotre on 01-Apr-11 03:38 AM
Client Config Timeout = Server Config Timeout = IIS Service Timeout = Works fine.
Thanks, that fixed the problem; the timeout no longer occurs.
All timeout settings must be the same. Makes sense.