【问题标题】:WCF Service Call Failing Due To Too Much Data Being Passed?由于传递的数据过多,WCF 服务调用失败?
【发布时间】:2012-02-17 19:48:48
【问题描述】:

我有一个用 C# 编写的 WCF 服务,该服务将实例化对象的集合传递给调用者(C# WPF 应用程序)。效果很好,但是如果我返回的集合有太多对象,则在大约 10 秒后调用在客户端失败并出现通用异常(其本身包含一系列通用内部异常)。下面是异常和内部异常:

{"接收到http://myserver/MyAppService/MyAppService.svc 的 HTTP 响应时发生错误。这可能是由于 服务端点绑定不使用 HTTP 协议。这可以 也可能是由于服务器中止了 HTTP 请求上下文 (可能是由于服务关闭)。查看服务器日志了解更多信息 详细信息。”}
{“底层连接已关闭:接收时发生意外错误。”}
{“无法从传输连接读取数据:现有连接被远程主机强行关闭。”}
{"一个现有的连接被远程主机强行关闭"}

这个问题是 100% 可复制的,并且肯定与集合的大小有关,而不是与内容有关。我知道这一点,因为如果我将单个集合分解为多个较小的集合并一次将它们传回一个,它就可以正常工作。只有当它们都在一起并且集合很大时才会有问题。

我尝试将客户端app.config 文件上的maxReceivedMessageSize 属性增加到2147483647,但错误仍然存​​在。还尝试增加超时时间,但没有影响。以下是app.config 文件中的属性。我尝试将以下几乎所有数字都增加到 2147483647,并尝试将 maxBufferPoolSize 更改为 0,但没有运气:

<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_iMyAppService" 
         closeTimeout="01:00:00" openTimeout="01:00:00" 
         receiveTimeout="01:00:00" sendTimeout="01:00:00"
         allowCookies="false" bypassProxyOnLocal="false" 
         hostNameComparisonMode="StrongWildcard"
         maxBufferSize="2147483647" maxBufferPoolSize="524288" 
         maxReceivedMessageSize="2147483647"
         messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
         useDefaultWebProxy="true">
      <readerQuotas 
           maxDepth="32" maxStringContentLength="8192" 
           maxArrayLength="16384" maxBytesPerRead="4096" 
           maxNameTableCharCount="16384" />
      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None"
          realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>
  </basicHttpBinding>
  <wsHttpBinding>
    <binding name="WSHttpBinding_iMyAppService" 
         closeTimeout="00:01:00" openTimeout="00:01:00" 
         receiveTimeout="00:10:00" sendTimeout="00:01:00"
         bypassProxyOnLocal="false" transactionFlow="false" 
         hostNameComparisonMode="StrongWildcard"
         maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647"
         messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
         allowCookies="false">
      <readerQuotas 
           maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
           maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      <reliableSession ordered="true" inactivityTimeout="00:10:00"
        enabled="false" />
      <security mode="Message">
        <transport clientCredentialType="Windows" proxyCredentialType="None"
          realm="" />
        <message clientCredentialType="Windows" negotiateServiceCredential="true"
          algorithmSuite="Default" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>
<client>
  <endpoint name="CurrencyConvertorSoap" 
      address="http://www.webservicex.net/CurrencyConvertor.asmx"
      binding="basicHttpBinding" 
      bindingConfiguration="CurrencyConvertorSoap"
      contract="CurrencyConverterService.CurrencyConvertorSoap" />

  <endpoint name="CurrencyConvertorSoap12" 
      address="http://www.webservicex.net/CurrencyConvertor.asmx"
      binding="customBinding" 
      bindingConfiguration="CurrencyConvertorSoap12"
      contract="CurrencyConverterService.CurrencyConvertorSoap" />

  <endpoint name="WSHttpBinding_iMyAppService"
      address="http://myserver/MyAppService/MyAppService.svc"
      binding="wsHttpBinding" 
      bindingConfiguration="WSHttpBinding_iMyAppService"
      contract="MyAppService.iMyAppService" >
    <identity>
      <dns value="localhost" />
    </identity>
  </endpoint>

  <endpoint name="BasicHttpBinding_iMyAppService" 
      address="http://myserver/MyAppService/MyAppService.svc"
      binding="basicHttpBinding" 
      bindingConfiguration="BasicHttpBinding_iMyAppService"
      contract="MyAppService.iMyAppService" />
</client>

我还可以更改或添加什么来完成这项工作?

谢谢!

【问题讨论】:

    标签: c# wpf wcf web-services endpoint


    【解决方案1】:

    它可能是 maxitemsinobjectgraph。启用 wcf 跟踪,您应该会在其中看到堆栈跟踪。

    【讨论】:

    • 该死......当我读到你的回复时,我真的很希望会是这样,但不幸的是没有去。除非我做得不对。但我将此添加到我的 app.config 中: 然后这个到我的端点线: behaviorConfiguration="Behaviors.EndpointBehavior" 但同样......不幸的是没有工作。同样的错误。不过感谢您的帮助。
    • 我不在我的电脑上,但我很确定您需要在主机客户端上进行设置?你试过了吗(@felan 的设置也是如此)。
    • 我尝试了 Felan 的建议,但不幸的是并没有解决问题。我尝试将 maxitemsinobjectgraph 的行为添加到服务器端 web.config,但没有这样做。我无法将 Felan 添加到服务器端,因为 web.config 在任何地方都没有这些选项,所以我不确定将它放在哪里。
    • 通过以下示例在服务器端也获得了 Felan。但仍然得到错误。
    • 明白了...终于。问题是在服务器端 web.config 上,行为 maxItemsInObjectGraph 必须是一种服务行为,而不是我所拥有的端点行为。谢谢
    【解决方案2】:

    我记得在类似的情况下,我不得不增加 maxArrayLength。

    【讨论】:

    • 我尝试将它增加到 2147483647,但得到了同样的错误。还是谢谢。
    • 你可能还需要增加 maxStringContentLength="8192" 我不会让 maxArrayLength 这么大。
    • 试过了......不幸的是不去。不过还是谢谢。
    猜你喜欢
    • 1970-01-01
    • 2011-05-18
    • 2015-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多