以编程方式设置 MaxItemsInObjectGraph

发布于 2024-10-10 18:17:57 字数 643 浏览 5 评论 0原文

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

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

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

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

雅心素梦 2024-10-17 18:17:57

在代码中:

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>

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>
孤芳又自赏 2024-10-17 18:17:57

您想要在 ServiceBehavior 属性中指定该属性。

 [ServiceContract]
 [ServiceBehavior(MaxItemsInObjectGraph=100000)] 
public interface IDataService 
{
   [OperationContract] 
   DataPoint[] GetData(); 
}

You want to specify the property in the ServiceBehavior attribute.

 [ServiceContract]
 [ServiceBehavior(MaxItemsInObjectGraph=100000)] 
public interface IDataService 
{
   [OperationContract] 
   DataPoint[] GetData(); 
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文