我有一个RESTful WCF服务,我收到以下错误:对象图中可以序列化或反序列化的最大项目数是'65536'.更改对象图或增加MaxItemsInObjectGraph配额.
我以为我已经解决了这个问题,但显然没有.这是我的代码:
我使用的.SVC文件使用这样的自定义工厂:
<%@ ServiceHost Language="C#" Debug="true" Service="myService" Factory="myCustomWebServiceHostFactory" %>
Run Code Online (Sandbox Code Playgroud)
这是自定义工厂的代码
public class myCustomWebServiceHost : WebServiceHost
{
public myCustomWebServiceHost()
{
}
public myCustomWebServiceHost(object singletonInstance, params Uri[] baseAddresses)
: base(singletonInstance, baseAddresses)
{
}
public myCustomWebServiceHost(Type serviceType, params Uri[] baseAddresses)
: base(serviceType, baseAddresses)
{
}
protected override void OnOpening()
{
foreach (var endpoint in Description.Endpoints)
{
var binding = endpoint.Binding as WebHttpBinding;
if (binding != null)
{
const int fiveMegaBytes = 5242880;
binding.MaxReceivedMessageSize = fiveMegaBytes;
binding.MaxBufferSize = fiveMegaBytes;
binding.MaxBufferPoolSize = fiveMegaBytes; …
Run Code Online (Sandbox Code Playgroud) 我有一个WCF服务的问题,它试图序列化太多的数据.从跟踪中我得到一个错误,该错误表示可以序列化或反序列化的元素的最大数量是'65536',尝试增加MaxItemsInObjectGraph配额.
所以我去修改了这个值,但它被忽略了(错误是相同的,具有相同的数字).这一切都是服务器端的.我暂时通过wget调用该服务.
我的网络配置是这样的:
<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>
Run Code Online (Sandbox Code Playgroud)
版本2,不工作:
<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 …
Run Code Online (Sandbox Code Playgroud)