WCF可能超出了我的响应大小
好的,我终于让我的WCF服务运行得很好了。这花了我一些时间,但我已经解决了几乎所有的问题。我现在唯一的问题就是这个 我的一个数据请求相当大,它包含大约37k的集合。我得到的错误如下WCF可能超出了我的响应大小,wcf,binding,maxreceivedmessagesize,Wcf,Binding,Maxreceivedmessagesize,好的,我终于让我的WCF服务运行得很好了。这花了我一些时间,但我已经解决了几乎所有的问题。我现在唯一的问题就是这个 我的一个数据请求相当大,它包含大约37k的集合。我得到的错误如下 The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an und
The socket connection was aborted. This could be caused by an error processing
your message or a receive timeout being exceeded by the remote host, or an
underlying network resource issue. Local socket timeout was '00:00:59.9840000'.
起初,您可能认为这是一个序列化问题,或者我需要更改绑定的容量
这是我的客户绑定
<netTcpBinding>
<binding name="MyCustomBinding" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00"
transactionFlow="false" transferMode="Buffered"
transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard" listenBacklog="10"
maxBufferPoolSize="1000000000" maxBufferSize="1000000000"
maxConnections="10" maxReceivedMessageSize="1000000000">
<readerQuotas maxDepth="32" maxStringContentLength="1000000000"
maxArrayLength="50000" maxBytesPerRead="4096"
maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Transport">
<transport clientCredentialType="Windows"
protectionLevel="EncryptAndSign" />
<message clientCredentialType="Windows" />
</security>
</binding>
</netTcpBinding>
因此,我将MaxReceiveMessageSize增加到可能的最高值2147483647。据此,。在我这样做之后,我可以安全地返回我的结果集。现在是关键,我得到了5000个结果,我在这个问题的顶部得到了我的初始异常
The socket connection was aborted. This could be caused by an error processing
your message or a receive timeout being exceeded by the remote host, or an
underlying network resource issue. Local socket timeout was '00:00:59.9840000'.
很明显,应用程序正在选择正确的绑定配置,否则它不会响应我在MaxReceiveMessageSize中的更改。因此,在这一点上,真正的问题是为什么它在这么小的变化上失败了 您正在服务器上使用netTcp绑定,但客户端配置了自定义绑定 这些应该匹配,这样它才能工作 这可能是因为您的自定义绑定非常接近netTcpbinding
也就是说,在小于64kb的给定大小下停止工作,可能是由于传输模式。Buffered将请求分解为块,只要有一个块可以工作,当超过一个时,配置中的差异会导致它失败。问题是您的服务实际上没有被调用
MyService
它也在一个名称空间中,这意味着您的服务配置实际上没有被使用-相反,默认端点正在与默认值连接
如果您将
服务
元素中的名称
属性更改为完全限定名称,则最后应选择正确的设置!这就是问题所在。我超出了客户端上的MaxItemsInObjectGraph值。因此,我需要将此行为添加到客户机配置文件中
服务器配置
<behaviors>
<serviceBehaviors>
<behavior name="serviceBehavior" >
<serviceMetadata />
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<behaviors>
<endpointBehaviors>
<behavior name="endpointBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint address="net.tcp://localhost:8732/RootAddress/EndpointLocation"
binding="netTcpBinding" bindingConfiguration="EndpointLocation"
behaviorConfiguration="endpointBehavior"
contract="ServiceReference1.IInterface" name="Interface">
<identity>
<userPrincipalName value="" />
</identity>
</endpoint>
</client>
客户端配置
<behaviors>
<serviceBehaviors>
<behavior name="serviceBehavior" >
<serviceMetadata />
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<behaviors>
<endpointBehaviors>
<behavior name="endpointBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint address="net.tcp://localhost:8732/RootAddress/EndpointLocation"
binding="netTcpBinding" bindingConfiguration="EndpointLocation"
behaviorConfiguration="endpointBehavior"
contract="ServiceReference1.IInterface" name="Interface">
<identity>
<userPrincipalName value="" />
</identity>
</endpoint>
</client>
然后在客户端配置文件端点上,我必须添加该行为
客户端配置
<behaviors>
<serviceBehaviors>
<behavior name="serviceBehavior" >
<serviceMetadata />
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<behaviors>
<endpointBehaviors>
<behavior name="endpointBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint address="net.tcp://localhost:8732/RootAddress/EndpointLocation"
binding="netTcpBinding" bindingConfiguration="EndpointLocation"
behaviorConfiguration="endpointBehavior"
contract="ServiceReference1.IInterface" name="Interface">
<identity>
<userPrincipalName value="" />
</identity>
</endpoint>
</client>
需要注意的是,我必须将行为部分完全添加到客户端的配置中。因为当我使用添加服务引用时,它不是生成的。之后,这项工作完美无瑕,我能够检索到我的37k自定义对象集合 请发布您的服务配置。它还需要设置为允许的大小;t告诉客户机正在使用什么绑定-它只是使用一个名为MyCustomBinding的配置设置。如果它是一个自定义绑定,那么所有设置都将在子绑定元素上,而不是绑定元素本身上。如何在客户机配置文件上指定netTcpBinding?@RichardBlewett谢谢,我对此有点困惑。到目前为止,在我的学习过程中,我还没有看到您在客户机配置中指定的位置。我理解您现在所说的。问题已更新。我只是从有问题的配置中提取了端点,因此它没有得到其父绑定。它使用的是我没有为这个问题输入我服务的完全限定名称。公司确实有必须遵守的隐私政策。我将用这些信息更新我的问题。正如我在问题开始时所说,我正在成功地来回传输数据,但传输量并不是非常大。但这可能是配置未在.NET 4下获取的症状-每个基址都有一个默认端点,因此您的服务中都有NetTcpBinding的默认设置,这意味着大小限制将是默认值(例如maxReceivedMessageSize为64k),很抱歉,我的头脑只是不理解这个解决方案。我在服务器配置中有7个其他端点遵循完全相同的模式,它们都可以工作。由于数据集相当大,我还必须为每一个增加maxReceivedMessageSize。否则,我将收到
已超过传入消息的最大消息大小配额(65536)。若要增加配额,请在相应的绑定元素上使用MaxReceivedMessageSize属性。
这样,您在每个端点上都有相同的约定,并且所有操作都通过其他端点(或者至少是具有相同约定的端点)工作?您是否已在服务中启用跟踪?这通常会突出显示触发问题的任何潜在异常。我还有其他几个合同,每个合同都有自己的端点,非常有效。我确实启用了跟踪let,但它似乎只是向我显示了与调试时完全相同的异常。