我在WCF调用上收到以下错误:
对象图中可序列化或反序列化的最大项数为“65536”
我已经阅读了大量的论坛帖子,其中许多人提到修改app.config和web.config以指定允许更大对象图的新行为 . 我已经这样做了,这就是我在这些文件中所拥有的:
App.Config on the WPF project:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="">
<dataContractSerializer maxItemsInObjectGraph="2147483646"/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="digiPM.Shell.LogOutPMSEMRService.PMSEMRLogOutService">
<!--<endpoint address="" binding="basicHttpBinding" contract="digiPM.Shell.LogOutPMSEMRService.IPMSEMRLogOutService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/Design_Time_Addresses/digiPM.Shell.LogOutPMSEMRService/PMSEMRLogOutService/" />
</baseAddresses>
</host>-->
<endpoint address="" binding="netTcpBinding" name="NetTcpBindingEndpoint" contract="digiPM.Shell.LogOutPMSEMRService.IPMSEMRLogOutService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" name="MexTcpBidingEndpoint" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8732/Design_Time_Addresses/digiPM.Shell.LogOutPMSEMRService/PMSEMRLogOutService/" />
</baseAddresses>
</host>
</service>
</services>
<!--binding info - removed this for the sake of readability for this post -->
web.config on the service project:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_Services" closeTimeout="01:10:00" openTimeout="01:10:00" receiveTimeout="01:10:00" sendTimeout="01:10:00" bypassProxyOnLocal="false"
transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647"
messageEncoding="Mtom" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
<readerQuotas maxDepth="4096" maxStringContentLength="2147483647" maxArrayLength="524288" maxBytesPerRead="524288" maxNameTableCharCount="524288" />
<reliableSession ordered="true" inactivityTimeout="01:10:00" enabled="false" />
<security mode="None">
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="digiPM.Service.Behavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="customObjectQuota">
<dataContractSerializer maxItemsInObjectGraph="2147483646"/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="digiPM.Service.Behavior"
name="digiPM.Service.AddressCrudService">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_Services"
name="AddressCrudServiceEndPoint" bindingNamespace="urn:Dawliasoft.Sculpture" contract="digiPM.Services.Contracts.IAddressCrudService" behaviorConfiguration="customObjectQuota" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" behaviorConfiguration="customObjectQuota" />
</service>
<!--<more services defined with same configuration as above..>-->
</services>
</system.serviceModel>
然而,这没有帮助 . 请注意,APP.CONFIG中引用的服务不是我遇到的服务问题 .
我也尝试了以下内容:
-
将这些属性添加到服务实现:[DataContract(IsReference = true)],[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any,MaxItemsInObjectGraph = 2147483646)]
-
编写了一个自定义DataContractSerializerOperationBehavior类,它设置了MaximumObjectsInGraph和IsReference行为 . 还添加了自定义属性以应用此服务实现 . 为了杂乱,我没有发布代码,但可以添加它,如果有人认为这将是有益的 .
思考?想法?我从哪里去?
提前致谢!
5 回答
我刚刚意识到你的WPF配置文件不对 . 所以,我删除了所有评论,因为他们假设有效的WCF配置 . 您的WPF配置文件不正确...它需要说“客户端”而不是服务...您是否在Visual Studio中使用“添加服务引用”?如果是这样,它应该为您创建正确的配置文件 .
否则,请参阅MSDN以获取WPF项目中客户端配置文件的正确格式 .
配置以下值为我解决了问题 .
客户端配置:
服务器配置:
您是否尝试过缓冲区和最大收到的邮件大小?
注意“dataContractSerializer”元素 . 在我的情况下,我得到了提到的错误,直到我把这个元素作为父元素“行为”的第一项 . 至少在客户端确实如此 .
您将在查询中返回一个通用列表或大小超过65536的数组 . 使用select top 60000或不添加超过60k的元素将解决您的问题 .