문제

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.

도움이 되었습니까?

해결책

https://docs.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)

다른 팁

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>

You want to specify the property in the ServiceBehavior attribute.

 [ServiceContract]
 [ServiceBehavior(MaxItemsInObjectGraph=100000)] 
public interface IDataService 
{
   [OperationContract] 
   DataPoint[] GetData(); 
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top