2010-02-24 54 views
7

我有一個WCF服務,它試圖序列化太多的數據的問題。從跟蹤我得到一個錯誤,說明可以序列化或非序列化的元素的最大數量是'65536',嘗試增加MaxItemsInObjectGraph配額。maxItemsInObjectGraph ignored

所以我去修改這個值,但它被忽略(錯誤是相同的,具有相同的數字)。所有這些都是服務器端。我現在通過wget調用服務。

我的web配置是這樣的:

<system.serviceModel> 
    <behaviors> 
    <serviceBehaviors> 
    <behavior name="AlgoMap.Web.MapService.MapServiceBehavior"> 
     <dataContractSerializer maxItemsInObjectGraph="131072" /> 
     <serviceMetadata httpGetEnabled="true" /> 
     <serviceDebug includeExceptionDetailInFaults="false" /> 
    </behavior> 
    </serviceBehaviors> 
    </behaviors> 
    <bindings> 
    <customBinding> 
    <binding name="customBinding0" closeTimeout="00:02:00" openTimeout="00:02:00" receiveTimeout="00:02:00"> 
     <binaryMessageEncoding> 
     <readerQuotas maxDepth="64" maxStringContentLength="16384" 
           maxArrayLength="16384" maxBytesPerRead="16384" 
           maxNameTableCharCount="16384" /> 
     </binaryMessageEncoding> 
     <httpTransport /> 
    </binding> 
    </customBinding> 
    </bindings> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" /> 
    <services> 
    <service behaviorConfiguration="AlgoMap.Web.MapService.MapServiceBehavior" 
    name="AlgoMap.Web.MapService.MapService"> 
    <endpoint address="" binding="customBinding" bindingConfiguration="customBinding0" 
    contract="AlgoMap.Web.MapService.MapService" /> 
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
    </service> 
    </services> 
</system.serviceModel> 



第2版,不工作之一:

<system.serviceModel> 
    <behaviors> 

    <endpointBehaviors> 
     <behavior name="AlgoMap.Web.MapService.MapServiceEndpointBehavior"> 
     <dataContractSerializer maxItemsInObjectGraph="131072" /> 
     </behavior> 
    </endpointBehaviors> 

    <serviceBehaviors> 
    <behavior name="AlgoMap.Web.MapService.MapServiceBehavior"> 
     <serviceMetadata httpGetEnabled="true" /> 
     <serviceDebug includeExceptionDetailInFaults="false" /> 
    </behavior> 
    </serviceBehaviors> 
    </behaviors> 
    <bindings> 
    <customBinding> 
    <binding name="customBinding0" closeTimeout="00:02:00" openTimeout="00:02:00" receiveTimeout="00:02:00"> 
     <binaryMessageEncoding> 
     <readerQuotas maxDepth="64" maxStringContentLength="16384" 
           maxArrayLength="16384" maxBytesPerRead="16384" 
           maxNameTableCharCount="16384" /> 
     </binaryMessageEncoding> 
     <httpTransport /> 
    </binding> 
    </customBinding> 
    </bindings> 

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" /> 
    <services> 
    <service behaviorConfiguration="AlgoMap.Web.MapService.MapServiceBehavior" 
    name="AlgoMap.Web.MapService.MapService"> 
    <endpoint 
     address="" binding="customBinding" bindingConfiguration="customBinding0" 
     contract="AlgoMap.Web.MapService.MapService" 
     behaviorConfiguration="AlgoMap.Web.MapService.MapServiceEndpointBehavior" /> 
    <endpoint 
     address="mex" binding="mexHttpBinding" contract="IMetadataExchange" 
     behaviorConfiguration="AlgoMap.Web.MapService.MapServiceEndpointBehavior" /> 
    </service> 
    </services> 
</system.serviceModel> 

誰能幫助? 謝謝!

+2

您還需要在客戶端配置中進行設置。 – flayn 2011-01-27 09:07:07

回答

10

放在web.config中的任何設置都被高興地忽略,我還沒有找到原因。但是我找到了一種解決方法,就是將MaxItemsInObjectGraph設置爲類裝飾。這完美的作品:

// MyService.svc 
// using... 

namespace MyNamespace { 
    [ServiceContract] 
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 
    [ServiceBehavior(MaxItemsInObjectGraph = 65536000)] 
    public class MyWebService { 

    [OperationContract] 
    [WebGet(UriTemplate = "tree/{sessionId}", ResponseFormat = WebMessageFormat.Json)] 
    public MyData GetTree(string sessionId) { 
    ... 
... 
+0

這是正確的!最後回答我一直在尋找... – zidane 2011-04-21 13:10:13

+0

我一直在尋找這個答案8小時,非常感謝。 – BryanGrimes 2012-01-09 17:23:18

1

可能它還小?你是否試圖給像655360000更大的價值?請注意,您應該更改客戶端和服務器的配置文件中的值。我的猜測是,你只改變了一部分;)

+2

不,它不小,它只是由服務器IGNORED。在例外情況下,我仍然可以看到默認限制。我沒有任何客戶端配置,因爲我通過wget調用了這個配置,在最終產品中,我將使用WebClient調用它。 – Palantir 2010-02-24 12:59:51

1

從谷歌的一個小搜索,似乎你是在錯誤的地方添加設置。

您需要在endPointBehaviors部分(而不是serviceBehaviors)中創建新的behavior

+0

試過,但結果相同。我把新的配置放在問題中... – Palantir 2010-02-24 12:50:57

3

我遇到了這個問題,以及在我的情況,我已經忘了把這個設置在我的客戶端app.config文件。

1

我有同樣的問題。在課堂上使用服務行爲屬性很好,這是有道理的。我更喜歡配置級別更改。我已經在客戶端(web.config)和服務級別(app.config)添加了配置條目。它能爲您提供幫助嗎?

相關問題