Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 由于传递的数据太多,WCF服务调用失败?_C#_Wpf_Wcf_Web Services_Endpoint - Fatal编程技术网

C# 由于传递的数据太多,WCF服务调用失败?

C# 由于传递的数据太多,WCF服务调用失败?,c#,wpf,wcf,web-services,endpoint,C#,Wpf,Wcf,Web Services,Endpoint,我有一个用C编写的WCF服务,它将实例化对象的集合传递给调用方一个C WPF应用程序。工作得很好,但是如果我返回的集合有太多的对象,则调用会在大约10秒后在客户端失败,出现一个泛型异常,该异常本身包含一系列泛型内部异常。以下是异常和内部异常: {接收对的HTTP响应时出错。这可能是由于 服务端点绑定未使用HTTP协议。这可能导致 也可能是由于服务器中止了HTTP请求上下文 可能是由于服务关闭。有关详细信息,请参阅服务器日志 详情} {基础连接已关闭:接收时发生意外错误。} {无法从传输连接读取数

我有一个用C编写的WCF服务,它将实例化对象的集合传递给调用方一个C WPF应用程序。工作得很好,但是如果我返回的集合有太多的对象,则调用会在大约10秒后在客户端失败,出现一个泛型异常,该异常本身包含一系列泛型内部异常。以下是异常和内部异常:

{接收对的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>
我还可以更改或添加什么来实现此功能



谢谢

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

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

我记得我以前在类似的情况下必须增加maxArrayLength。

我记得我在类似的情况下必须增加maxArrayLength。

该死的……当我阅读您的回复时,我真的很有希望这样做,但不幸的是,没有成功。除非我做得不对。但我将其添加到app.config:中,然后将其添加到我的端点行:behaviorConfiguration=Behaviors.EndpointBehavior,但很遗憾,再次……没有起作用。同样的错误。谢谢你的帮助。我现在不在电脑前,但我很确定你需要在主机和客户端上进行设置?你有没有试过这对@felan的设置是一样的。我试过felan的建议,但不幸的是没有解决它。我尝试将maxitemsinobjectgraph的行为添加到服务器端web.config,但没有成功。但我无法将Felan添加到服务器端,因为web.config中没有这些选项,所以我不确定将其放置在何处。通过以下示例也可以将Felan添加到服务器端。但还是有错误,终于有了。问题在于,在服务器端web.config上,行为maxItemsInObjectGraph必须是一个servicebehavior,而不是我所拥有的端点行为。谢谢你…当我读到你的回复时,我真的很有希望,但不幸的是没有成功。除非我做得不对。但我将其添加到app.config:中,然后将其添加到我的端点行:behaviorConfiguration=Behaviors.EndpointBehavior,但很遗憾,再次……没有起作用。同样的错误。谢谢你的帮助。我现在不在电脑前,但我很确定你需要在主机和客户端上进行设置?你有没有试过这对@felan的设置是一样的。我试过felan的建议,但不幸的是没有解决它。我尝试将maxitemsinobjectgraph的行为添加到服务器端web.config,但没有成功。但我无法将Felan添加到服务器端,因为web.config中没有这些选项,所以我不确定将其放置在何处。通过以下示例也可以将Felan添加到服务器端。但还是有错误,终于有了。问题在于,在服务器端web.config上,行为maxItemsInObjectGraph必须是一个servicebehavior,而不是我所拥有的端点行为。ThanksI尝试将其增加到2147483647,但得到了相同的错误。无论如何,谢谢。您可能还必须增加maxStringContentLength=8192,我不会让maxArrayLength那么大。尝试过了……很遗憾,没有成功。谢谢。我试着把它增加到2147483647,但是得到了同样的错误。无论如何,谢谢。您可能还必须增加maxStringContentLength=8192,我不会让maxArrayLength那么大。尝试过了……很遗憾,没有成功。谢谢你。