【问题标题】:"The server did not provide a meaningful reply" with large message content“服务器没有提供有意义的回复”,邮件内容大
【发布时间】:2018-05-10 11:57:37
【问题描述】:

我刚刚阅读了很多解决问题的可能性

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

WCF 异常,

但没有一个对我有用。 我有一个通过 EntityFramework 执行 linq 查询的服务方法,并且用户可以选择启用或禁用导航属性的加载。这是函数。

public List<DataTransferObjects.Equipment> GetEquipments(bool Include = true)
{
    using (Entities.DBEntities context = new Entities.DBEntities())
    {
        return Include ? (from equipment
                          in context.Equipments
                          .Include(equipment => equipment.A)
                          .Include(equipment => equipment.B)
                          .Include(equipment => equipment.C)
                          .Include(equipment => equipment.D)
                          select equipment)?.ToDataTransferObjects<Entities.Equipment, DataTransferObjects.Equipment>().ToList()
                       :
                         (from equipment
                          in context.Equipments
                          select equipment)?.ToDataTransferObjects<Entities.Equipment, DataTransferObjects.Equipment>().ToList()
    }
}

当我通过生成的服务引用使用 false Include 值调用该函数时,它可以正常工作,但是当 Include 为 true 时,它​​会引发异常。我确定问题是消息的大小或一些相关的大小问题,因为如果我更改函数以请求前 20 条记录它工作正常(整个表包含 94 条记录),所以工作 linq 查询。

(from equipment
 in context.Equipments
 .Include(equipment => equipment.A)
 .Include(equipment => equipment.B)
 .Include(equipment => equipment.C)
 .Include(equipment => equipment.D)
 select equipment).Take(20)?.ToDataTransferObjects<Entities.Equipment, DataTransferObjects.Equipment>().ToList()

配置如下

<system.serviceModel>
<bindings>
  <netTcpBinding>
    <binding name="DefaultBinding" transferMode="Buffered" maxBufferSize="2147483646" maxBufferPoolSize="2147483646" transactionProtocol="OleTransactions" maxReceivedMessageSize="2147483646">
      <readerQuotas maxDepth="2147483646" maxStringContentLength="2147483646" maxArrayLength="2147483646" maxBytesPerRead="2147483646" maxNameTableCharCount="2147483646" />
      <!--<security mode="Transport"> Nothing changed with this option
        <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
        <message clientCredentialType="Windows"/>
      </security>-->
    </binding>
  </netTcpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true" />
<behaviors>
  <serviceBehaviors>
    <behavior name="DefaultBehaviour">
      <dataContractSerializer maxItemsInObjectGraph="2147483646" />
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
      <serviceAuthorization impersonateCallerForAllOperations="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<services>
  <service behaviorConfiguration="DefaultBehaviour" name="ServiceLibrary.Service">
    <endpoint address="WCFService" binding="netTcpBinding" bindingConfiguration="DefaultBinding" contract="ServiceLibrary.IService" />
    <host>
      <baseAddresses>
        <add baseAddress="net.tcp://localhost:8080" />
      </baseAddresses>
    </host>
  </service>
</services>
</system.serviceModel>

【问题讨论】:

    标签: c# wcf nettcpbinding


    【解决方案1】:

    这里有几件事需要考虑

    1. 客户端和服务器都负责设置大小等配置值,如果您担心此类事情,请确保正确设置客户端配置

    2. 如果您认为这是一个大小问题,只限于一个或几个记录,这应该会给您一个很好的指示。

    3. 我的钱不是大小设置(MaxReceivedMessageSize 错误或类似的东西),更可能是包含的嵌套合约之一中的序列化问题。尝试一次实现一个包含

      • 尝试找出导致问题的相关合同。它可能只是缺少一些简单的东西。
      • 再一次,尝试从可行的方法开始,并不断增加复杂性,直到找到问题为止

    作为奖励提示,这完全是对三元运算符的滥用,看起来很恶心 :) 只是说...

    祝你好运

    【讨论】:

    • 我可以使用 DataContractSerializer 序列化结果列表,二进制结果是一个长度为 1839955 的数组。
    • 客户端的配置包含相同的相关属性。我可以使用多条消息请求每条记录,但在这种情况下,时间开销很大,因此第一条消息包含前 20 条记录,第二条消息包含第二条 20 条记录,依此类推。最好是每条记录都有一条消息。
    猜你喜欢
    • 2011-02-08
    • 1970-01-01
    • 2012-11-19
    • 1970-01-01
    • 1970-01-01
    • 2011-08-13
    • 1970-01-01
    • 2018-11-16
    • 1970-01-01
    相关资源
    最近更新 更多