问题描述
限时送ChatGPT账号..我的 WCF 服务出现问题,该服务试图序列化过多数据.从跟踪中我得到一个错误,指出可以序列化或反序列化的最大元素数为65536",请尝试增加 MaxItemsInObjectGraph 配额.
I have a problem with a WCF service, which tries to serialize too much data. From the trace I get an error which says that the maximum number of elements that can be serialized or unserialized is '65536', try to increment the MaxItemsInObjectGraph quota.
所以我去修改了这个值,但它只是被忽略了(错误是相同的,具有相同的数字).所有这些都是服务器端的.我暂时通过 wget 调用该服务.
So I went and modified this value, but it is just ignored (the error is the same, with the same number). All this is server-side. I am calling the service via wget for the moment.
我的网络配置是这样的:
My web config is like this:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="AlgoMap.Web.MapService.MapServiceBehavior">
<dataContractSerializer maxItemsInObjectGraph="131072" />
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<customBinding>
<binding name="customBinding0" closeTimeout="00:02:00" openTimeout="00:02:00" receiveTimeout="00:02:00">
<binaryMessageEncoding>
<readerQuotas maxDepth="64" maxStringContentLength="16384"
maxArrayLength="16384" maxBytesPerRead="16384"
maxNameTableCharCount="16384" />
</binaryMessageEncoding>
<httpTransport />
</binding>
</customBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<services>
<service behaviorConfiguration="AlgoMap.Web.MapService.MapServiceBehavior"
name="AlgoMap.Web.MapService.MapService">
<endpoint address="" binding="customBinding" bindingConfiguration="customBinding0"
contract="AlgoMap.Web.MapService.MapService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
<小时><小时><小时>
第 2 版,也不起作用:
Version 2, not working either:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="AlgoMap.Web.MapService.MapServiceEndpointBehavior">
<dataContractSerializer maxItemsInObjectGraph="131072" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="AlgoMap.Web.MapService.MapServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<customBinding>
<binding name="customBinding0" closeTimeout="00:02:00" openTimeout="00:02:00" receiveTimeout="00:02:00">
<binaryMessageEncoding>
<readerQuotas maxDepth="64" maxStringContentLength="16384"
maxArrayLength="16384" maxBytesPerRead="16384"
maxNameTableCharCount="16384" />
</binaryMessageEncoding>
<httpTransport />
</binding>
</customBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<services>
<service behaviorConfiguration="AlgoMap.Web.MapService.MapServiceBehavior"
name="AlgoMap.Web.MapService.MapService">
<endpoint
address="" binding="customBinding" bindingConfiguration="customBinding0"
contract="AlgoMap.Web.MapService.MapService"
behaviorConfiguration="AlgoMap.Web.MapService.MapServiceEndpointBehavior" />
<endpoint
address="mex" binding="mexHttpBinding" contract="IMetadataExchange"
behaviorConfiguration="AlgoMap.Web.MapService.MapServiceEndpointBehavior" />
</service>
</services>
</system.serviceModel>
有人可以帮忙吗??谢谢!!
Can anyone help?? Thanks!!
推荐答案
web.config 中的任何设置都被愉快地忽略了,我还没有找到原因.但是我找到了一个解决方法,就是将 MaxItemsInObjectGraph 作为类装饰.这完美无缺:
Any setting put in the web.config were happily ignored, I haven't found out why. But I found a workaround, that is, to put the MaxItemsInObjectGraph as a class decoration. This works flawlessly:
// MyService.svc
// using...
namespace MyNamespace {
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(MaxItemsInObjectGraph = 65536000)]
public class MyWebService {
[OperationContract]
[WebGet(UriTemplate = "tree/{sessionId}", ResponseFormat = WebMessageFormat.Json)]
public MyData GetTree(string sessionId) {
...
...
这篇关于maxItemsInObjectGraph 被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论