WCF 服务导致错误"..."在服务器计算机中'65536 ...'对象图中可以序列化或反序列化的最大项数



我开发了一个控制台应用程序,该应用程序在远程服务器上使用 WCF 服务。此应用程序发送的项目大约超过 50000。当我在自己的计算机上运行应用程序时,没有错误。传输成功。

但是,当我将应用程序复制到 Windows Server 2008 计算机然后运行它时,会发生错误:

尝试序列化参数 http://tempuri.org/:req 时出错。InnerException 消息是"对象图中可以序列化或反序列化的最大项数为'65536'。更改对象图或增加 MaxItemsInObjectGraph 配额。'. 有关更多详细信息,请参阅 InnerException。

顺便说一下,WCF 服务位于远程桌面上,不受我的控制。我确定,在配置中存在这部分

<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</serviceBehaviors>
</behaviors>

Shorty,我的控制台应用程序使用WCF在我的桌面上工作,但它在我的Windows Server 2008机器中不起作用。

您还需要在客户端添加类似的配置。下面是示例配置。请根据您的服务详细信息进行适当的更改。

<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IMyService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="128" maxStringContentLength="2147483647" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://XXXX/MyService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMyService" contract="MyServiceReference.IMyService" name="BasicHttpBinding_IMyService" behaviorConfiguration="MyServiceBehaviour"/>
</client>
<behaviors>
<endpointBehaviors>
<behavior name="MyServiceBehaviour">
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>

最新更新