3

好的,所以我终于让我的 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 中的更改。所以在这一点上,真正的问题是为什么它会因为如此小的变化而失败。

4

3 回答 3

3

FINALLY! Ok so this was the problem. I was exceeding the, MaxItemsInObjectGraph value on the client end. So I needed to add this behavior to the clients configuration file.

Server config

<behaviors>
  <serviceBehaviors>
    <behavior name="serviceBehavior" >
      <serviceMetadata />
      <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>

Client Config

<behaviors>
<endpointBehaviors>
  <behavior name="endpointBehavior">
    <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
  </behavior>
</endpointBehaviors>
</behaviors>

Then on the clients configuration file endpoint, I had to add that behavior.

Client config

<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>

Just to note, I had to add the behaviors section entirely to the config on the client side. As it was not generated when I use Add Service Reference. This worked flawlessly afterwards, and I was able to retrieve my 37k custom object collection.

于 2012-02-24T16:13:37.130 回答
0

问题是您的服务实际上并没有MyService在命名空间中调用它,这意味着您的服务配置实际上并没有被使用 - 相反,默认端点正在与默认值连接

如果您将元素中的name属性更改service为完全限定名称,它应该选择正确的设置

于 2012-02-23T22:32:01.563 回答
0

您在服务器上使用 netTcp 绑定,但客户端配置了自定义绑定。

这些应该匹配,才能正常工作。

这完全可行可能是因为您的自定义绑定非常接近 netTcpbinding。

那是在小于 64kb 的给定大小下停止工作,可能是由于传输模式。Buffered 将请求分块分解,只要有一个块它可以工作,当超过一个块时,配置中的差异会导致它失败。

于 2012-02-23T22:30:24.193 回答