I've an application using WCF on client and server side. I get errors when I return a large amount of data:
There was an error while trying to serialize parameter http://tempuri.org/:GetCurrentDatabaseObjectsResult. The InnerException message was 'Maximum number of items that can be serialized or deserialized in an object graph is '65535'. Change the object graph or increase the MaxItemsInObjectGraph quota. '. Please see InnerException for more details.
(the main important thing is that I've to increase the MaxItemsInObjectGraph).
I found this article here: How can I set the maxItemsInObjectGraph property programmatically from a Silverlight Application? but it seems this is only for the client side and I need to do this on the server.
In code:
foreach (OperationDescription op in factory.Endpoint.Contract.Operations)
{
DataContractSerializerOperationBehavior dataContractBehavior =
op.Behaviors.Find<DataContractSerializerOperationBehavior>()
as DataContractSerializerOperationBehavior;
if (dataContractBehavior != null)
{
dataContractBehavior.MaxItemsInObjectGraph = 100000;
}
}
In configuration:
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaivor">
<serviceAuthorization impersonateCallerForAllOperations="True" />
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceThrottling maxConcurrentCalls="2147483647" />
<dataContractSerializer maxItemsInObjectGraph="65775" />
</behavior>
</serviceBehaviors>
</behaviors>
https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/specifying-data-transfer-in-service-contracts#controlling-the-serialization-process
Go down to "Controlling the serialization process" heading (or do a search for the maxItemsInObjectGraph)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With