C# &引用;服务器没有提供有意义的回复“quot;具有较大的消息内容
我刚刚读了很多解决问题的可能性 “服务器未提供有意义的答复;这可能是由于 由于契约不匹配、会话过早关闭或内部 服务器错误“ WCF例外 但是没有一个为我工作。 我有一个通过EntityFramework执行linq查询的服务方法,用户可以选择启用或禁用导航属性的加载。下面是函数C# &引用;服务器没有提供有意义的回复“quot;具有较大的消息内容,c#,wcf,nettcpbinding,C#,Wcf,Nettcpbinding,我刚刚读了很多解决问题的可能性 “服务器未提供有意义的答复;这可能是由于 由于契约不匹配、会话过早关闭或内部 服务器错误“ WCF例外 但是没有一个为我工作。 我有一个通过EntityFramework执行linq查询的服务方法,用户可以选择启用或禁用导航属性的加载。下面是函数 public List<DataTransferObjects.Equipment> GetEquipments(bool Include = true) { using (Entities.DBEn
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()
}
}
public List getdevices(bool Include=true)
{
使用(Entities.DBEntities context=new Entities.DBEntities())
{
退货包括来自设备的退货
在上下文中。设备
.包括(设备=>设备A)
.包括(设备=>设备B)
.包括(设备=>设备C)
.包括(设备=>设备D)
选择设备)?.ToDataTransferObjects().ToList()
:
(来自设备)
在上下文中。设备
选择设备)?.ToDataTransferObjects().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()
(来自设备)
在上下文中。设备
.包括(设备=>设备A)
.包括(设备=>设备B)
.包括(设备=>设备C)
.包括(设备=>设备D)
选择设备)。采取(20)?.ToDataTransferObjects().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>
这里有几件事需要考虑
MaxReceivedMessageSize
错误或类似错误),更可能是其中一个嵌套契约中的序列化问题。尝试一次实现一个includes来
- 试着找出导致问题的相关合同。它可能只是缺少了一些简单的东西李>
- 再一次,试着从一些有效的东西开始,不断增加复杂性,直到你发现问题
祝你好运我能够用DataContractSerializer序列化结果列表,结果是一个长度为1839955的数组。客户端的配置包含相同的相关属性。我可以用多条消息请求每个记录,但在这种情况下,时间开销很大,因此第一条消息包含前20条记录,第二条消息包含后20条记录,依此类推。最好是每一张唱片都有一条信息。