好的,所以我终于让我的 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
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 容量的唯一原因是,如果我将结果限制为 1000 个集合,我就没有问题。当涉及到大型通信时,除了绑定之外,我还需要担心其他配置吗?
谢谢!
编辑 1
此外,我已将绑定中每个超时值的超时更改为 00:10:00,但这似乎没有什么不同。服务器的响应时间少于 5 秒。
编辑 2
服务配置。
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<system.web>
<compilation debug="true" />
</system.web>
<system.serviceModel>
<bindings />
<client />
<services>
<service behaviorConfiguration="serviceBehavior"
name="MyService">
<clear />
<endpoint address="MyCustomObject" binding="netTcpBinding"
bindingConfiguration="" name="MyCustomObject"
contract="MyService.IContract" >
</endpoint>
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8732/MyService/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<serviceMetadata />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
编辑 3
请理解,我没有包含有关该服务模型的任何敏感信息,因此它们已被替换为 MyCustom***。再次,请仔细阅读问题我正在通过其他端点成功地使用此服务来回传输数据,没有问题。另外,就像我上面所说的,如果我将结果限制为 1000,我可以通过该端点传输数据。
编辑 4
好的,让我更清楚。客户端应用程序正在获取正确的绑定。我知道的原因是,当我的应用程序在集合中返回大约 4500 个结果的结果集时,给了我以下异常。
The maximum message size quota for incoming messages (65536) has
been exceeded. To increase the quota, use the MaxReceivedMessageSize
property on the appropriate binding element.
所以我将 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 中的更改。所以在这一点上,真正的问题是为什么它会因为如此小的变化而失败。