【问题标题】:WCF - When object to transfer has a list of more than 127 objectsWCF - 当要传输的对象具有超过 127 个对象的列表时
【发布时间】:2013-06-18 13:59:29
【问题描述】:

我将 WCF 与 Code First 结合使用(VS 2012、.NET 4.0、WCF 5)。除非我想转移一个大物体,否则一切正常。它包含许多其他对象的列表。每个对象只有很小的内容。如果此列表超过 127 个对象,则会出现异常:

服务器没有提供有意义的回复;这可能是由 合同不匹配、会话过早关闭或内部 服务器错误。

我通过减少数据库中的列数发现了这一点(尝试和错误)。

我在客户端使用如下配置:

  <system.serviceModel>
    <bindings>
      <netTcpBinding>
        <binding name="NetTcpBinding_****_Service" closeTimeout="00:00:10"
          openTimeout="00:00:10" receiveTimeout="00:05:00" sendTimeout="00:05:00"
          maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
            maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
        </binding>
      </netTcpBinding>
    </bindings>
    <client>
      <endpoint address="net.tcp://localhost:8000/****" binding="netTcpBinding"
        bindingConfiguration="****" contract="****"
        name="NetTcpBinding_****Service">
        <identity>
          <userPrincipalName value="****" />
        </identity>
      </endpoint>
    </client>
  </system.serviceModel>

服务器配置如下:

  <system.serviceModel>
    <bindings>
      <netTcpBinding>
        <binding name="NetTcpBinding_****_Service" closeTimeout="00:00:10"
          openTimeout="00:00:10" receiveTimeout="00:05:00" sendTimeout="00:05:00"
          transferMode="Buffered" maxBufferPoolSize="2147483647" maxBufferSize="2147483647"
          maxConnections="0" maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="100000" maxStringContentLength="100000"
            maxArrayLength="100000" maxBytesPerRead="100000" maxNameTableCharCount="100000" />
          <reliableSession enabled="false" />
        </binding>
      </netTcpBinding>
    </bindings>
    <services>
      <service name="****">
        <endpoint address="" binding="netTcpBinding" bindingConfiguration="NetTcpBinding_****_Service"
          contract="****" />
        <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
          contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost:8000/****" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="false"/>
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

请原谅掩盖了一些名字。我需要避免人们可以从这些名称中得出关于项目的推论。 :D

【问题讨论】:

    标签: wcf configuration code-first


    【解决方案1】:

    首先,在服务器端设置此属性(仅用于开发)

    <serviceDebug includeExceptionDetailInFaults="true" />
    

    指定是否将托管异常信息包含在返回给客户端以进行调试的 SOAP 错误的详细信息中。

    在处理您的请求时确定有问题,但您没有任何调试信息。这就是为什么你必须设置这个属性。您也可以打开 WCF 跟踪,但有点困难。

    WCF 有很多配额:配额是一个硬限制,一旦超过配额值,就阻止使用额外的资源。

    在发送大数据时特别需要注意两个配额:maxReceivedMessageSize 和 MaxItemsInObjectGraph。

    【讨论】:

      猜你喜欢
      • 2015-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-02
      • 1970-01-01
      • 2023-03-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多