ASP.Net Web服务超时问题

4
我有一个ASP.Net Web服务。大约有150个客户端应用程序每分钟连续访问Web服务。
在这种情况下,有些人可以获得服务,而有些人则不断出现超时异常。这是客户端和服务之间的数据传输服务。
引用如下:
请求通道在等待回复后超时00:09:59.9531343。增加传递给Request的超时值或增加Binding上的SendTimeout值。分配给此操作的时间可能是较长超时的一部分。
我已经在客户端增加了时间,但没有成功。
Web服务的Web.Config如下:
<?xml version="1.0"?>

<configuration>


    <configSections>
      <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
        <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
          <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
          <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
            <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere" />
            <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
            <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
            <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
          </sectionGroup>
        </sectionGroup>
      </sectionGroup>

      <!-- For Logging Servic-->
      <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net"/>

    </configSections>


  <!-- #User Settings -->
  <appSettings>


    <add key="SqlServerDBConnectionString" value="Data Source=MyServerName;Initial Catalog=dbName;User ID=myUserId;Password=myPassword;"/>

    <add key="ActiveDBConnectionString" value="SqlServerDBConnectionString"/>


    <!--<add key="DetailedLog" value="Yes"/>-->
    <add key="DetailedLog" value="No"/>

  </appSettings>
  <!--#User end-->

    <connectionStrings/>

    <system.web>
        <!-- 
            Set compilation debug="true" to insert debugging 
            symbols into the compiled page. Because this 
            affects performance, set this value to true only 
            during development.
        -->
        <compilation debug="true">

          <assemblies>
            <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
            <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
            <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
          </assemblies>

        </compilation>
        <!--
            The <authentication> section enables configuration 
            of the security authentication mode used by 
            ASP.NET to identify an incoming user. 
        -->
        <!--<authentication mode="Windows" />-->
        <!--
            The <customErrors> section enables configuration 
            of what to do if/when an unhandled error occurs 
            during the execution of a request. Specifically, 
            it enables developers to configure html error pages 
            to be displayed in place of a error stack trace.

        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
            <error statusCode="403" redirect="NoAccess.htm" />
            <error statusCode="404" redirect="FileNotFound.htm" />
        </customErrors>
        -->
      <customErrors mode="Off" />
      <pages>
        <controls>
          <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
          <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        </controls>
      </pages>

      <httpHandlers>
        <remove verb="*" path="*.asmx"/>
        <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
      </httpHandlers>
      <httpModules>
        <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      </httpModules>
      <httpRuntime maxRequestLength="2097151" />

    </system.web>

    <system.codedom>
      <compilers>
        <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4"
                  type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <providerOption name="CompilerVersion" value="v3.5"/>
          <providerOption name="WarnAsError" value="false"/>
        </compiler>
      </compilers>
    </system.codedom>

    <!-- 
        The system.webServer section is required for running ASP.NET AJAX under Internet
        Information Services 7.0.  It is not necessary for previous version of IIS.
    -->
    <system.webServer>
      <validation validateIntegratedModeConfiguration="false"/>
      <modules>
        <remove name="ScriptModule" />
        <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      </modules>
      <handlers>
        <remove name="WebServiceHandlerFactory-Integrated"/>
        <remove name="ScriptHandlerFactory" />
        <remove name="ScriptHandlerFactoryAppServices" />
        <remove name="ScriptResource" />
        <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode"
             type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode"
             type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      </handlers>
    </system.webServer>

    <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
          <assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/>
          <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
        </dependentAssembly>
        <dependentAssembly>
          <assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/>
          <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
        </dependentAssembly>
      </assemblyBinding>
    </runtime>

  <!-- Logging Section Start-->
  <log4net>
    <root>
      <level value="DEBUG" />
      <appender-ref ref="DataSyncLog" />
    </root>

    <logger >
      <level value="ALL" />
    </logger>

    <appender name="DataSyncLog" type="log4net.Appender.RollingFileAppender" >
      <param name="File" value="Log.log" />
      <param name="AppendToFile" value="true" />

      <rollingStyle value="Size" />
      <maxSizeRollBackups value="10" />
      <maximumFileSize value="10MB" />
      <staticLogFileName value="true" />
      <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value="%-5p%d{ yyyy-MM-dd hh:mm:ss} – %m%n" />
      </layout>
      <lockingModel type="log4net.Appender.FileAppender+MutexLock" />
    </appender>




  </log4net>
  <!-- Logging Section End-->

</configuration>

有人能告诉我如何克服这种情况吗?

(请注意,此处只是逐句翻译,我无法理解“这种情况”具体指什么。如果需要更准确的翻译,请提供更多上下文)
1个回答

0
从ASP.Net Web服务中超时
您会收到此错误,因为通过网络传输的数据超过了指定时间内所能处理的数据量。
一个显而易见的解决方案是增加超时时间。但不建议作为直接解决方案
首先,您需要检查要传递多少数据?您的客户端是否真的需要所有这些数据? 其次,您的客户端是否愿意等待10分钟来回调?
在大多数情况下,答案将是NO,因此您应该考虑使用分页和分块发送数据。如果这不合适,请将数据裁剪到用户的即时需求。
您可以在发送之前使用某种压缩,并在接收时解压缩(如果您是应用程序的用户)。

谢谢Ehsan。是的,系统中存在压缩和解压功能。客户端和服务之间传输的数据不超过1.5 MB,但并非每次都有这么多数据传输。有时会传输这么多数据。但是,如果150个客户端中的50个同时尝试传输此数量的数据,会发生什么?通常情况下,传输的数据量为50-100 kB。 客户端将从服务中获取其所需的精确数据。 - Rezoan
对于50-100kb的数据,完全不应该有任何问题。即使是1.5Mb的数据也可以顺利传输。这意味着瓶颈在你的代码的其他地方,可能是网络延迟。每个客户端都将获得自己的连接,因此不会影响其他客户端。 - Ehsan
当有15-20个客户端时,系统运行得非常完美,但是对于100或150个客户端,我发现有2或3个客户端总是从服务中获得超时异常。我已经理解他们无法获得服务,但无法找到解决方法。 我已经模拟了少量客户端(10个),每个客户端每次强制传输10MB数据(不一定需要),系统响应良好。 - Rezoan
这可能是您的服务器一次允许的最大带宽。 - Ehsan
是的,你说得对。当限制带宽时,可能会出现这个问题。老实说,我昨天测试过了。但是从IIS中看到Web服务托管的位置:最大带宽(字节/秒):4294967295和最大并发连接数:4294967295。 - Rezoan
这是IIS允许的,而不是您的服务器允许的。请与您的托管提供商确认。 - Ehsan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接