c# - WCF 超时异常! mscorlib.dll 中出现类型为 'System.TimeoutException' 的异常

标签 c# asp.net .net wcf

我在 asp.net web 应用程序中使用 wcf 服务,wcf 服务中的函数有时需要超过 1 分钟才能响应,在这种情况下会引发异常。我不确定如何增加此请求超时,我尝试了 wcf 配置文件但不起作用我是否也必须在我的 Web 应用程序端执行此操作?如果是这样,如何?请帮忙!

异常详情: 附加信息:请求 channel 在 00:00:59.8689077 之后等待回复时超时。增加传递给 Request 调用的超时值或增加 Binding 上的 SendTimeout 值。分配给此操作的时间可能是较长超时的一部分。

wcf web.config:

<?xml version="1.0"?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5.2"/>
    <httpRuntime targetFramework="4.5.2"/>
    <httpModules>
      <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"/>
    </httpModules>
  </system.web>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding receiveTimeout="00:05:00" sendTimeout="00:05:00" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text">
          <readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
        <add binding="basicHttpsBinding" scheme="https"/>
    </protocolMapping>    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
  </system.serviceModel>
  <system.webServer>

      <security>
        <requestFiltering>
          <requestLimits maxAllowedContentLength="524288000"/>
        </requestFiltering>
      </security>

    <modules runAllManagedModulesForAllRequests="true">
      <remove name="ApplicationInsightsWebTracking"/>
      <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"
        preCondition="managedHandler"/>
    </modules>
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true"/>
    <validation validateIntegratedModeConfiguration="false"/>
  </system.webServer>

</configuration>

asp.net webapp web.config:

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <system.web>

    <compilation debug="true" targetFramework="4.5.2" />
    <httpRuntime targetFramework="4.5.2" maxRequestLength="1048576" />
    <httpModules>
      <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
    </httpModules>
  <pages>
      <controls>
        <add tagPrefix="gmaps" namespace="Subgurim.Controles" assembly="GMaps" />
      </controls>
    </pages></system.web>
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
    </compilers>
  </system.codedom>
  <system.webServer>


    <security>
        <requestFiltering>
            <requestLimits maxAllowedContentLength="524288000"/>
        </requestFiltering>
     </security>

    <validation validateIntegratedModeConfiguration="false" />
    <modules>
      <remove name="ApplicationInsightsWebTracking" />
      <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
    </modules>
  </system.webServer>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IService1" />
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:35800/Service1.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1" name="BasicHttpBinding_IService1" />
    </client>
  </system.serviceModel>
<appSettings>
    <!-- Add your Google Maps API Key from Google -->
    <add key="googlemaps.subgurim.net" value="" />
    <!-- And add your Commercial Key from Subgurim if you have purchased one -->
    <add key="googlemaps.subgurim.net_Commercial" value="" />
  </appSettings></configuration>

最佳答案

也尝试在您的 asp.net 网络配置中设置超时

这是来 self 的一位消费者的示例,它使用流式数据,因此超时至关重要

<system.serviceModel>
  <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_IStreamed" transferMode="Streamed" messageEncoding="Mtom"  maxReceivedMessageSize="67108864" maxBufferSize="65536"
              closeTimeout="00:01:00" openTimeout="00:01:00"
              receiveTimeout="00:10:00" sendTimeout="00:01:00"/>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://localhost:#####/streamed.svc" binding="basicHttpBinding"
            bindingConfiguration="BasicHttpBinding_IStreamed"
            contract="SyncSVC.IStreamed" name="BasicHttpBinding_IStreamed" />
    </client>
</system.serviceModel>

关于c# - WCF 超时异常! mscorlib.dll 中出现类型为 'System.TimeoutException' 的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36869205/

相关文章:

javascript - JQuery 最接近的元素,来自 GridView 中的 TextBox

c# - 需要代理身份验证(Forefront TMG 需要授权才能完成请求。拒绝访问 Web 代理筛选器。)

c# - 目标 BeforeBuild 在 csproj 中不起作用

c# - 如何在 ReSharper 8 中禁用 “Press tab to replace highlighted range” 消息?

c# - 如何使用正则表达式匹配不以空格开头的字符串?

c# - 带有 where 子句的 LINQ 语句使执行变慢

c# - 无法在 gridview 中访问 TextArea 中的文本

.net - ASHX HTTP 处理程序和表单例份验证

c# - 键盘上的特殊键

c# - C# 上的注册表和 Wow6432Node