Click here to Skip to main content
15,886,094 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
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.

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:

C#
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
<?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>



Thanks, any help will be appreciated.
Posted

The problem has been fixed:

Client Timeout Config = Server Timeout Config = IIS Service Timeout Setting

All three must be equal.
 
Share this answer
 
Try using SqlDataReader.BeginExecuteReader. It's the asynch version of ExecuteReader and requires a bit more work pon your part, but it may address your problem. Having X million records to search doesn't help anything either.
 
Share this answer
 
v4
Comments
jarrodk1011101101 30-Mar-11 3:33am    
Thanks for your response. I would consider your solution if it was only the SQL routine firing asyncronously but because the call to the service is asyncronous it would be a case of:

A. Get result async from B.

B. Get SQL result async and return to A.

A. will still timeout waiting for a result from B. after one minute, regardless of B. executing asyncronously.

Any idea why the timeout is occuring please?
0) Change your stored proc to change the query based on whether the specified date range results in a single day, or a range of days.

1) Adjust your query so that it's built dynamically, and it either queries for a range of dates, or for a single date, depending on how the specified date range is specified

2) Set the appropriate date column as an index (if it isn't already)

3) Call this web service method with a single date, like so:

C#
DateTime currentDate = calStart.Selecteddate.Value;
do
{
    // calling the stored proc with the same two dates will cause the query to 
    // just look for that date instead of checking the date range
    webservice.GetSparBatteriesReport1Async(currentDate, currentDate);
    currentDate.AddDays(1);
} (while currentDate <= calEnd.SelectedDate.Value);


Of course, you'll have to take steps to handle the asynchronous nature of calling a web service, like handling the AsyncComplete event (or whatever it's called).
 
Share this answer
 
Comments
jarrodk1011101101 29-Mar-11 11:45am    
Thanks for your response. Yes, perhaps some of my sql queries could use some tweaking so that they execute quicker. The queries worked fine on smaller data but since an import of 20 million records this morning, the queries are taking a lot longer. But what I'm really after is why the timeout is occuring even though I've specified a longer timeout in the config files. Any ideas there? Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900