我知道这已被问过几次了,但我在stackoverfolow上尝试了所有的解决方案,但是它们似乎都没有用,所以在这里:
我有一个服务(在NetTCP绑定上运行)只是等待连接并在调用时将工作分配给另一个服务,它传递的数据很大,因此我收到了这个错误:
对象图中可以序列化或反序列化的最大项目数为'65536'“
下面是我的配置:
<services>
<service behaviorConfiguration="CoreBehavior" name="PrepService">
<endpoint address="net.tcp://localhost/Preparation"
binding="netTcpBinding"
contract="IWorkManagerService"
bindingConfiguration="CoreTcpBinding"/>
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="CoreTcpBinding" closeTimeout="00:10:00" openTimeout="00:10:00"
sendTimeout="00:10:00" maxBufferSize="2147483647"
maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="64" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="None"/>
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="CoreBehavior">
<serviceMetadata httpGetEnabled="false" />
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
正如你在我的CoreTcpBinding中看到的那样,我已经大大超出了所有的配置值,但我仍然得到同样的错误,我只是难过为什么它默认为“65536”?
调用上面定义的服务的服务(客户端)具有以下配置:
<services>
<service behaviorConfiguration="CoreBehavior" name="AssignmentService">
<endpoint address="net.tcp://localhost:8001/Assignment"
binding="netTcpBinding"
contract="IWorkerService"
bindingConfiguration="CoreTcpBinding"/>
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="CoreTcpBinding"
maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="None"/>
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="CoreBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
客户端照常通过代理与服务器通信:
var proxy = new PrepServiceProxy(new NetTcpBinding(), new EndpointAddress(ServiceAddress));
Proxy Code :
public PrepServiceProxy(Binding binding, EndpointAddress remoteAddress) : base(binding, remoteAddress)
{
var netTcpBinding = binding as NetTcpBinding;
if (netTcpBinding != null)
(netTcpBinding).Security.Mode = SecurityMode.None;
}
答案 0 :(得分:3)
您必须在客户端和服务器端配置它。确保两边都有dataContractSerializer maxItemsInObjectGraph =“2147483647”。