【问题标题】:WCF client hangs on call with lots of dataWCF 客户端挂起大量数据
【发布时间】:2014-08-14 16:36:08
【问题描述】:

我在 Azure VM 上有一个 WCF 服务,并且我的方法在服务器端需要花费大量时间(取决于我发送的数据大小)。

问题是有时我的客户端在调用此方法时会挂起。我知道该方法完成并到达最后一行,但我的客户从未得到响应。当我向该方法传递大量数据并且需要大约 1 小时才能完成时,就会发生这种情况。如果该方法在几分钟内完成,则客户端成功获得响应。

这是我的 web.config

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

  <configSections>

    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <section name="PrintCloud.WebService.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
      <section name="PrintCloud.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
    </sectionGroup>
  </configSections>

  <system.diagnostics>

    <sources>
      <source propagateActivity="true" name="System.ServiceModel" switchValue="Warning,ActivityTracing">
        <listeners>
          <add type="System.Diagnostics.DefaultTraceListener" name="Default">
            <filter type=""/>
          </add>
          <add name="ServiceModelTraceListener">
            <filter type=""/>
          </add>
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add initializeData="C:\Logs\PrintCloudLog.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="ServiceModelTraceListener" traceOutputOptions="Timestamp">
        <filter type=""/>
      </add>
    </sharedListeners>
    <trace>
      <listeners>
        <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=2.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
          <filter type=""/>
        </add>
      </listeners>
    </trace>
  </system.diagnostics>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
  </appSettings>

  <system.web>
    <compilation targetFramework="4.5" debug="true"/>
    <httpRuntime targetFramework="4.5"/>
    <customErrors mode="Off"/>
  </system.web>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="LargeSettings" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" openTimeout="00:10:00" closeTimeout="00:10:00" sendTimeout="00:10:00" receiveTimeout="00:10:00" transferMode="Streamed">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service name="PrintCloud.PrintCloudService">
        <endpoint binding="basicHttpBinding" bindingConfiguration="LargeSettings"
          name="Default" contract="PrintCloud.PrintCloudService" />
      </service>
    </services>
    <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="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https"/>
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true"/>
  </system.serviceModel>
  <system.webServer>
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="2147483647" />
      </requestFiltering>
    </security>
    <modules runAllManagedModulesForAllRequests="true"/>
    <!--
        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"/>
  </system.webServer>

</configuration>

和客户端配置:

binding.OpenTimeout = new TimeSpan(100, 0, 0);
binding.CloseTimeout = new TimeSpan(100, 0, 0);
binding.SendTimeout = new TimeSpan(100, 0, 0);
binding.ReceiveTimeout = new TimeSpan(100, 0, 0);

根本没有例外。客户端根本没有得到服务器的响应。

这是我调用的方法:

public Domain.DocumentGenerationResponse GenerateDocument(Guid id, Domain.PrintOptions printOptions, Domain.Job job)

it returns only several short strings. job arguments contains 1000 documents (each document has an image 111Kb)

【问题讨论】:

  • 请与我们分享您的代码,以便我们了解您在做什么。
  • 客户端最终会抛出超时吗?一种想法是,您和服务器之间可能存在代理服务器,该服务器在一定时间后中止/取消请求。
  • 不,它已经挂了 3 个小时,没有异常。 @mikey
  • Azure 不会在一段时间后切断空闲连接吗?比如 20 分钟?

标签: c# wcf azure


【解决方案1】:

您应该检查超时或消息大小配置。检查此MSDN 链接以获取超时配置,并检查此link 以获取消息配额大小配置。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-11-13
    • 1970-01-01
    • 1970-01-01
    • 2012-12-16
    • 1970-01-01
    • 1970-01-01
    • 2015-08-20
    • 1970-01-01
    相关资源
    最近更新 更多