我正在尝试传输大约7000-8000个不大的对象(每个对象实例只有9个属性)。有没有人知道为什么当我开始检索超过5000个对象时,我会收到连接错误?它完美无缺,直到达到数据大小的某个阈值。
我通过WCF的TCP服务绑定公开了对这些对象的检索。我有以下示例配置:
<bindings>
<netTcpBinding>
<binding name="NetTcpBindingConfig"
openTimeout="00:01:00"
sendTimeout="00:05:00"
closeTimeout="00:01:00"
maxBufferPoolSize="2147483647"
maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
<security>
<transport/>
</security>
</binding>
</netTcpBinding>
</bindings>
<services>
<service behaviorConfiguration="ServiceBehavior"
name="TestService">
<endpoint address=""
binding="netTcpBinding"
bindingConfiguration="NetTcpBindingConfig"
contract="ServiceInterfaces.ITestService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex"
binding="mexTcpBinding"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8526/TestService" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="Services.ServiceBehavior">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
从我的.NET代码中,我使用带有以下示例代码的ChannelFactory调用该服务:
using (ChannelFactory<ITestervice> channel = new ChannelFactory<ITestService>(BindingConfig, "net.tcp://localhost:8526/TestService"))
{
ITestService testService = channel.CreateChannel();
toReturn = testService.LoadAll();
channel.Close();
}
BindingConfig对象是我的代码中的NetTcpBinding属性,填充为'new NetTcpBinding(“NetTcpBindingConfig”)'。我的客户端绑定与我的WCF TCP服务绑定完全相同。
任何人都可以提供有关如何检索所有数据的任何见解(我的当前设置似乎我的最大限制是~5000个对象)?任何帮助深表感谢。感谢。
编辑: 如果有人遇到此问题,请参阅有关MaxItemsInObjectGraph的已接受解决方案。但是,如果您使用来自客户端的ChannelFactory来使用您的服务,请参阅以下代码以使其正常工作:
foreach (OperationDescription operation in channel.Endpoint.Contract.Operations)
{
DataContractSerializerOperationBehavior dataContractBehavior = operation.Behaviors[typeof(DataContractSerializerOperationBehavior)] as DataContractSerializerOperationBehavior;
if (dataContractBehavior != null)
dataContractBehavior.MaxItemsInObjectGraph = int.MaxValue;
}
答案 0 :(得分:8)
考虑增加MaxItemsInObjectGraph配额(其默认值为64k)。它应该在服务器端和客户端。请参阅示例配置: