我知道这已经被问过几次了,但是我尝试了 stackoverfolow 上的所有解决方案,但它们似乎都不起作用,所以就这样了:
我有一个服务(在 NetTCP 绑定上运行),它只是等待连接并在调用时将工作分配给另一个服务,它传递的数据很大,因此我收到此错误:
对象图中可以序列化或反序列化的最大项目数为 '65536'”</p>
下面是我的配置:
<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;
}