13

我在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行爲。還添加了自定義屬性以應用此服務實現。爲了混亂,我沒有發佈代碼,但可以添加它,如果有人認爲這將是有益的。

想法?想法?我從哪裏出發?

在此先感謝!

回答

4

我剛剛意識到你的WPF配置文件不正確。所以,我刪除了我的所有評論,因爲他們假設有效的WCF配置。你的WPF配置文件是不正確的......它需要說「客戶端」而不是服務......你在Visual Studio中使用「添加服務引用」嗎?如果是這樣,它應該爲您創建正確的配置文件。

否則,請參閱MSDN瞭解您的WPF項目中客戶端配置文件的正確格式。

+0

我在config文件中添加了更多來自system.service的模型節 – Scot

+0

aha!...我想你可能會發生什麼...我會檢查添加「客戶端」部分。僅供參考 - 這是我從另一個團隊繼承的項目,我不知道他們使用哪種方法爲WPF應用程序生成app.config文件。 – Scot

+0

請嘗試在visual studio中添加一個「Service Reference」,並且在添加服務引用之前不要忘記刪除app.config中的整個「system.servicemodel」部分...您的生活將會變得更加簡單...然後你可以通過添加'maxItemsInObjectGraph'的東西來定製你的配置文件...祝你好運。 – Nabheet

5

您是否嘗試過提高緩衝區和最大接收郵件大小?

maxBufferSize="6553600" maxBufferPoolSize="52428800" maxReceivedMessageSize="6553600" 
+0

這是否將在服務主機項目的web.config?或客戶端的app.config?或兩者? – Scot

+0

在應用程序的app.config上。 – Josh

+0

這對我來說是未知領域... :-)這是正確的方法嗎? <結合maxBufferPoolSize = 「2147483646」 MAXBUFFERSIZE = 「2147483646」 maxReceivedMessageSize = 「2147483646」/> Scot

12

配置下面的值爲我解決了這個問題。

客戶端配置:

<system.serviceModel> 
<bindings> 
<basicHttpBinding> 
    <binding name="BasicHttpBinding_IManagementService" closeTimeout="00:01:00" 
    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
    maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647" 
    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" 
    useDefaultWebProxy="true"> 
    <readerQuotas maxDepth="128" maxStringContentLength="2147483647" 
     maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
    <security mode="None"> 
     <transport clientCredentialType="None" proxyCredentialType="None" 
     realm="" /> 
     <message clientCredentialType="UserName" algorithmSuite="Default" /> 
    </security> 
    </binding> 
</basicHttpBinding> 
</bindings> 
<client> 
<endpoint address="http://XXXX/ManagementService.svc" 
    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IManagementService" 
    contract="ManagementServiceReference.IManagementService" 
    name="BasicHttpBinding_IManagementService" behaviorConfiguration="ManagementServiceBehaviour"/> 
</client> 
<behaviors> 
<endpointBehaviors> 
    <behavior name="ManagementServiceBehaviour"> 
    <dataContractSerializer maxItemsInObjectGraph="2147483647"/> 
    </behavior> 
</endpointBehaviors> 
</behaviors> 

服務器配置:

<system.serviceModel> 
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
<behaviors> 
<serviceBehaviors> 
    <behavior name="ManagementServiceBehaviour"> 
    <serviceDebug includeExceptionDetailInFaults="true" /> 
    <serviceMetadata httpGetEnabled="true" /> 
    <dataContractSerializer ignoreExtensionDataObject="false" maxItemsInObjectGraph="2147483646" /> 
    </behavior> 
    <behavior name=""> 
    <serviceMetadata httpGetEnabled="true" /> 
    <serviceDebug includeExceptionDetailInFaults="false" /> 
    </behavior> 
</serviceBehaviors> 
</behaviors> 
<bindings> 
<basicHttpBinding> 
    <binding name="BasicHttpBinding" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" closeTimeout="01:50:00" openTimeout="01:50:00" sendTimeout="01:50:00" receiveTimeout="01:50:00" > 
    <readerQuotas maxDepth="128" maxStringContentLength="8388608" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
    </binding> 
</basicHttpBinding> 
</bindings> 

<services> 
<service behaviorConfiguration="ManagementServiceBehaviour" name="BusinessLogic.Facade.EntityFacade.Services.ManagementService"> 
    <endpoint binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding" contract="BusinessLogic.Facade.EntityFacade.Contracts.IManagementService"> 
    <identity> 
     <dns value="" /> 
    </identity> 
    </endpoint> 
</service> 
</services> 
</system.serviceModel> 
+0

嗨,我嘗試使用你的代碼(綁定和行爲,但我得到這個錯誤信息: **內容類型text/xml; charset = UTF-8不支持服務**。 你有任何線索爲什麼我得到這個錯誤信息? – NoOne

0

你是返回一個泛型列表或具有尺寸超過65536在查詢一個數組,使用選擇頂部60000或不添加超過60k元素將解決您的問題。

1

請注意「dataContractSerializer」元素。 在我的情況下,我得到的錯誤提到,直到我把這個元素作爲父元素「行爲」的第一項。 至少在客戶端確實如此。

相關問題