我有一个在客户端和服务器端使用 WCF 的应用程序。当我返回大量数据时出现错误:

尝试序列化参数时出错 http://tempuri.org/:GetCurrentDatabaseObjectsResult. 。InnerException 消息是“对象图中可以序列化或反序列化的最大项目数为“65535”。更改对象图或增加 MaxItemsInObjectGraph 配额。'。请参阅 InnerException 了解更多详细信息。

(最重要的是我必须增加 MaxItemsInObjectGraph)。

我在这里找到这篇文章: 如何从 Silverlight 应用程序以编程方式设置 maxItemsInObjectGraph 属性? 但似乎这仅适用于客户端,我需要在服务器上执行此操作。

有帮助吗?

其他提示

在代码:

foreach (OperationDescription op in factory.Endpoint.Contract.Operations)
{
    DataContractSerializerOperationBehavior dataContractBehavior =
                op.Behaviors.Find<DataContractSerializerOperationBehavior>()
                as DataContractSerializerOperationBehavior;
    if (dataContractBehavior != null)
    {
        dataContractBehavior.MaxItemsInObjectGraph = 100000;
    }
}

在配置:

<behaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehaivor">
      <serviceAuthorization impersonateCallerForAllOperations="True" />
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
      <serviceThrottling maxConcurrentCalls="2147483647" />
      <dataContractSerializer maxItemsInObjectGraph="65775" />
    </behavior>
  </serviceBehaviors>
</behaviors>

您想在ServiceBehavior属性来指定属性。

 [ServiceContract]
 [ServiceBehavior(MaxItemsInObjectGraph=100000)] 
public interface IDataService 
{
   [OperationContract] 
   DataPoint[] GetData(); 
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top