Bra*_*don 3 c# wcf web-services wcf-binding
我试图传输大约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>
Run Code Online (Sandbox Code Playgroud)
从我的.NET代码中,我使用ChannelFactory调用该服务,其中包含以下示例代码:
using (ChannelFactory<ITestervice> channel = new ChannelFactory<ITestService>(BindingConfig, "net.tcp://localhost:8526/TestService"))
{
ITestService testService = channel.CreateChannel();
toReturn = testService.LoadAll();
channel.Close();
}
Run Code Online (Sandbox Code Playgroud)
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;
}
Run Code Online (Sandbox Code Playgroud)