HTTP请求已超过分配的超时 [英] HTTP request has exceeded the allotted timeout

查看:127
本文介绍了HTTP请求已超过分配的超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
请帮助我解决此问题:
一分钟后,Web服务超时,我对配置文件的更改似乎不起作用.正在执行的存储过程大约需要5分钟才能执行.其他耗时不到一分钟的查询可以毫无问题地执行.它托管在IIS7上.

服务代码:

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:

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>




谢谢,我们将不胜感激.




Thanks, any help will be appreciated.

推荐答案

问题已解决:

客户端超时配置=服务器超时配置= IIS服务超时设置

这三个必须相等.
The problem has been fixed:

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

All three must be equal.


尝试使用SqlDataReader.BeginExecuteReader.它是ExecuteReader的异步版本,需要您付出更多的努力,但它可能会解决您的问题.拥有X百万条记录来搜索也无济于事.
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.


0)更改存储的proc以根据指定的日期范围是一天还是一天来更改查询.天数范围.

1)调整查询,使其动态生成,并查询日期范围或单个日期,具体取决于指定日期范围的方式

2)将相应的日期列设置为索引(如果尚未设置)

3)用单个日期调用此Web服务方法,如下所示:

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:

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



当然,您将必须采取步骤来处理调用Web服务的异步性质,例如处理AsyncComplete事件(或任何被调用的事件).



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


这篇关于HTTP请求已超过分配的超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆