2013-07-12 19 views
10

Otrzymuję następujący błąd podczas próby dostępu do mojej usługi WCF.Ustawienie WCF MaxItemsInObjectGraph nie działa

"Maksymalna liczba elementów, które można serializować lub deserializować na wykresie obiektów to" 65536 ". Zmień wykres obiektu lub zwiększenia limitu MaxItemsInObjectGraph

Robi rozeznanie, wygląda na to wszystko, co musisz zrobić, to ustawienie będzie wyższa wartość jest aktualizacja. To właśnie próbuję zrobić, ale ustawienie nie wydaje się być odczytane z konfiguracji. Wciąż otrzymuję ten sam wyjątek z wartością 65536.

Poszedłem za instrukcjami znalezionymi pod tym Link, ale nie mam szczęścia.

Oto, co skonfigurowałem na Web.Config Service WCF.

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

To jest to, co jest w app.config Klienta:

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

i wreszcie, mam następujący atrybut na usługi WCF samego:

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

Pomimo powyższych konfiguracjach Nadal dostaję wyjątek narzekający na wartość 65536. Dlaczego żadne z tych ustawień nie jest używane przez aplikacje? Czy jest jeszcze coś, co trzeba gdzieś ustawić?

Odpowiedz

5

Musiał przejść jądro i zaktualizować plik machine.config;

Directions Here

Istotą tego celu jest dodanie następujących do sekcji „system.serviceModel”.

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

Jesteś na dobrej drodze! Wszystko co musiałem zrobić, to dodać opis do zachowania

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

A potem na punkcie końcowym dodać

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

Dzięki! Uratowałem mi dużo czasu :) –

0

Napisałem program do zmiany konfiguracyjne dla tego urządzenia, ponieważ wsparcie. Działa to dla mnie, ale nie zrobiłem wielu testów.

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

miałem ten sam problem, nie było pewne teksty stałe w klasie powracającej .Co odkryło, że nie mogą być puste. Sprawdź, czy masz jakiekolwiek wyliczenia, które mają zostać zwrócone.