【发布时间】:2012-09-09 19:06:44
【问题描述】:
我知道这个问题已经被问过几次了,但是我在 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;
}
【问题讨论】:
-
我看到在您的服务器配置中,端点合同属性不是完全限定名称。确保它是完全限定的(即需要在接口名称之前有命名空间)
标签: wcf datacontractserializer