2013-07-12 8 views
10

Ho ricevuto il seguente errore nel tentativo di accedere al servizio WCF.WCF MaxItemsInObjectGraph impostazione non funzionante

'Il numero massimo di elementi che possono essere serializzati o deserializzati in un oggetto grafico è' 65536 '. Modifica il grafico dell'oggetto o aumenta la quota MaxItemsInObjectGraph

Facendo qualche ricerca, sembra che tutto ciò che devo fare sia aggiornare questa impostazione per essere un valore più alto. Questo è quello che sto cercando di fare, ma l'impostazione sembra non essere letta dalla configurazione. Continuo a ricevere la stessa eccezione con il valore 65536 al suo interno.

Ho seguito le istruzioni trovate a questo Link, ma non sto avendo fortuna.

Ecco cosa ho configurato sul Web.Config del servizio WCF.

<behaviors> 
     <serviceBehaviors> 
      <behavior name="metadataBehavior"> 
       <serviceMetadata httpGetEnabled="true" httpGetUrl="" /> 
       <serviceDebug includeExceptionDetailInFaults="false" /> 
       <dataContractSerializer maxItemsInObjectGraph="2147483646"/> 
      </behavior> 
     </serviceBehaviors> 
    </behaviors> 

Questo è ciò che è in app.config del Cliente:

 <behaviors> 
     <serviceBehaviors> 
      <behavior> 
       <serviceMetadata httpGetEnabled="True" /> 
       <serviceDebug includeExceptionDetailInFaults="False" /> 
      </behavior> 
     </serviceBehaviors> 
     <endpointBehaviors> 
      <behavior > 
       <dataContractSerializer maxItemsInObjectGraph="2147483646"/> 
      </behavior> 
     </endpointBehaviors> 
    </behaviors> 

E, infine, ho il seguente attributo al servizio WCF in sé:

[ServiceBehavior(MaxItemsInObjectGraph = 2147483646, IncludeExceptionDetailInFaults = true)] 

Nonostante le configurazioni di cui sopra , Ricevo comunque un'eccezione che si lamenta del valore 65536. Perché nessuna di queste impostazioni viene utilizzata dalle applicazioni? C'è qualcos'altro che deve essere impostato da qualche parte?

risposta

5

Ha dovuto andare nucleare e aggiornare that machine.config;

Directions Here

L'essenza di esso è quello di aggiungere quanto segue alla sezione "system.serviceModel".

<commonBehaviors> 
     <endpointBehaviors> 
     <dataContractSerializer maxItemsInObjectGraph="2147483647" /> 
     </endpointBehaviors> 
     <serviceBehaviors> 
     <dataContractSerializer maxItemsInObjectGraph="2147483647" /> 
     </serviceBehaviors> 
    </commonBehaviors> 
8

Tu eri sulla strada giusta! Tutto quello che doveva fare era aggiungere un nome al comportamento

<behavior name="MyBehavior"> 
    <dataContractSerializer maxItemsInObjectGraph="2147483646"/> 
</behavior> 

e poi sul punto finale aggiungere

<endpoint .... behaviorConfiguration="MyBehavior"/> 
+0

Grazie! Mi ha salvato un sacco di tempo :) –

0

ho scritto un programma per modificare i file di configurazione della macchina per questo, perché il supporto. Funziona per me, ma non ho fatto tonnellate di test.

using System; 
using System.IO; 
using System.Linq; 
using System.Xml.Linq; 

namespace FixMachineConfigBehavior 
{ 
    class Program 
    { 
     public static XElement IfNotExistsAdd(XDocument xd, XElement rootElement, string childName, XElement newChild) 
     { 
      if (rootElement.Elements(childName).Count() == 0) 
      { 
       Console.WriteLine(" adding " + childName + " node..."); 
       rootElement.Add(newChild); 
      } 

      return rootElement.Element(childName); 
     } 

     static void Main(string[] args) 
     { 
      foreach (var file in Directory.EnumerateFiles(Environment.GetEnvironmentVariable("windir") + @"\Microsoft.NET\","machine.config",SearchOption.AllDirectories)) 
      { 
       Console.WriteLine("fixing: " + file); 

       TimeSpan t = DateTime.UtcNow - new DateTime(1970, 1, 1); 
       double ms = t.TotalMilliseconds; 

       File.Copy(file, file + "." + ms + ".bak", true); 

       var xd = XDocument.Load(file); 

       XElement i = xd.Root; 
       i = IfNotExistsAdd(xd, i, "system.serviceModel", new XElement("system.serviceModel")); 
       i = IfNotExistsAdd(xd, i, "commonBehaviors", new XElement("commonBehaviors")); 
       i = IfNotExistsAdd(xd, i, "endpointBehaviors", new XElement("endpointBehaviors")); 
       i = IfNotExistsAdd(xd, i, "dataContractSerializer", new XElement("dataContractSerializer", new XAttribute("maxItemsInObjectGraph", Int32.MaxValue))); 

       xd.Save(file); 
      } 

      Console.ReadLine(); 
     } 
    } 
} 
0

Ho avuto lo stesso problema e provato diverse opzioni, ma ho trovato la soluzione qui: https://msdn.microsoft.com/en-us/library/ms732038.aspx

In "Controllo del processo di serializzazione".

Aggiunta ...

[ServiceBehavior (MaxItemsInObjectGraph = 100000)] classe mio servizio ...

buona fortuna

0

Ho avuto lo stesso problema, c'era qualche enumerazioni in classe ritorno .Ciò che ha scoperto non possono essere nulli. Controlla se hai Enumchi che devono essere restituiti.