我在WCF呼叫接收以下錯誤:WCF錯誤「可以在一個對象圖被序列或反串行化的項目的最大數目是‘65536’」
項目的最大數量可以被序列化或在 對象圖反序列化是「65536」
我讀過一噸的論壇帖子,其中許多人提修改的app.config和web.config中指定新的行爲,以便更大的對象圖。我已經做了,這是我在這些文件:
App.Config中的WPF項目:
<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>
:對服務項目
<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
但是,這並沒有幫助。請注意,APP.CONFIG中引用的服務不是我遇到問題的服務。
我也試過如下:
加入這些屬性的服務實現:[DataContract(IsReference =真)],[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any,MaxItemsInObjectGraph = 2147483646)]
寫了一個自定義的DataContractSerializerOperationBehavior類,它設置了MaximumObjectsInGraph和IsReference行爲。還添加了自定義屬性以應用此服務實現。爲了混亂,我沒有發佈代碼,但可以添加它,如果有人認爲這將是有益的。
想法?想法?我從哪裏出發?
在此先感謝!
我在config文件中添加了更多來自system.service的模型節 – Scot
aha!...我想你可能會發生什麼...我會檢查添加「客戶端」部分。僅供參考 - 這是我從另一個團隊繼承的項目,我不知道他們使用哪種方法爲WPF應用程序生成app.config文件。 – Scot
請嘗試在visual studio中添加一個「Service Reference」,並且在添加服務引用之前不要忘記刪除app.config中的整個「system.servicemodel」部分...您的生活將會變得更加簡單...然後你可以通過添加'maxItemsInObjectGraph'的東西來定製你的配置文件...祝你好運。 – Nabheet