我在进行一个WCF调用时遇到了以下错误:
对象图中可以序列化或反序列化的最大项数为'65536'
我阅读了很多论坛帖子,其中许多帖子提到需要修改app.config和web.config文件来指定新的行为以允许更大的对象图。我已经完成了这些操作,并在这些文件中添加了以下内容:
WPF项目的App.Config:
<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:
<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行为,并添加自定义属性以将其应用于服务实现。出于杂乱的考虑,我没有发布代码,但如果有人认为有益,我可以添加它。 想法?建议?我接下来该做什么?
提前感谢!