wcf-configuration - WCF MaxItemsInObjectGraph设置不起作用

标签 wcf-configuration

尝试访问WCF服务时出现以下错误。

'Maximum number of items that can be serialized or deserialized in an object graph is '65536'. Change the object graph or increase the MaxItemsInObjectGraph quota



做一些研究,看来我需要做的就是将这个设置更新为更高的值。这是我要尝试执行的操作,但是似乎未从配置中读取该设置。我不断收到与65536值相同的异常。

我按照在Link上找到的说明进行操作,但是没有运气。

这是我在WCF服务的Web.Config上配置的内容。
    <behaviors>
        <serviceBehaviors>
            <behavior name="metadataBehavior">
                <serviceMetadata httpGetEnabled="true"  httpGetUrl="" />
                <serviceDebug includeExceptionDetailInFaults="false" />
                <dataContractSerializer maxItemsInObjectGraph="2147483646"/>
            </behavior>
        </serviceBehaviors>
    </behaviors>

这是客户端的app.config中的内容:
        <behaviors>
        <serviceBehaviors>
            <behavior>
                <serviceMetadata httpGetEnabled="True" />
                <serviceDebug includeExceptionDetailInFaults="False" />
            </behavior>
        </serviceBehaviors>
        <endpointBehaviors>
            <behavior >
                <dataContractSerializer maxItemsInObjectGraph="2147483646"/>
            </behavior>
        </endpointBehaviors>
    </behaviors>

最后,我在WCF服务本身上具有以下属性:
[ServiceBehavior(MaxItemsInObjectGraph = 2147483646, IncludeExceptionDetailInFaults = true)]

尽管进行了上述配置,但我仍然收到有关65536值的异常投诉。为什么应用程序没有使用这些设置中的任何一个?还有其他需要设置的地方吗?

最佳答案

您在正确的轨道上!
您要做的就是为行为添加一个名称

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

然后在端点上添加
<endpoint .... behaviorConfiguration="MyBehavior"/>

关于wcf-configuration - WCF MaxItemsInObjectGraph设置不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17622408/

相关文章:

wcf - WCF:配置已知类型

c# - App.config 之外的 WCF ChannelFactory 配置?

c# - 组合/聚合许多底层服务响应的 WCF 路由器

WCF 测试客户端 - 有什么方法可以将服务/设置保存到文件中以便以后轻松重新加载?

c# - Config 中 System.Object 的 WCF 已知类型

c# - 在 WCF 中找不到引用契约(Contract)的默认端点元素

c# - netTCP 绑定(bind) Soap 安全协商失败

.net - 在控制台应用程序中托管 WCF 服务时出现 IMetadataExchange MEX 端点错误