WCF错误"对象图中可以序列化或反序列化的最大项数为'65536'"



我在WCF调用中收到以下错误:

对象中可序列化或反序列化的最大项数对象图为"65536"

我读了很多论坛帖子,其中很多都提到修改app.config和web。配置来指定新的行为以允许更大的对象图。我已经完成了,这就是我在这些文件中的内容:

应用程序。WPF项目配置:

<system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior name="">
      <serviceMetadata httpGetEnabled="false" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="">
      <dataContractSerializer maxItemsInObjectGraph="2147483646"/>
    </behavior>
  </endpointBehaviors>
</behaviors>
<services>
  <service name="digiPM.Shell.LogOutPMSEMRService.PMSEMRLogOutService">
    <!--<endpoint address="" binding="basicHttpBinding" contract="digiPM.Shell.LogOutPMSEMRService.IPMSEMRLogOutService">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8732/Design_Time_Addresses/digiPM.Shell.LogOutPMSEMRService/PMSEMRLogOutService/" />
      </baseAddresses>
    </host>-->
    <endpoint address="" binding="netTcpBinding" name="NetTcpBindingEndpoint" contract="digiPM.Shell.LogOutPMSEMRService.IPMSEMRLogOutService">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" name="MexTcpBidingEndpoint" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="net.tcp://localhost:8732/Design_Time_Addresses/digiPM.Shell.LogOutPMSEMRService/PMSEMRLogOutService/" />
      </baseAddresses>
    </host>
  </service>
</services>
<!--binding info - removed this for the sake of readability for this post -->

网络。

<system.serviceModel>
<bindings>
  <wsHttpBinding>
      <binding name="WSHttpBinding_Services" closeTimeout="01:10:00" openTimeout="01:10:00" receiveTimeout="01:10:00" sendTimeout="01:10:00" bypassProxyOnLocal="false" 
               transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647" 
               messageEncoding="Mtom" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
          <readerQuotas maxDepth="4096" maxStringContentLength="2147483647" maxArrayLength="524288" maxBytesPerRead="524288" maxNameTableCharCount="524288" />
          <reliableSession ordered="true" inactivityTimeout="01:10:00" enabled="false" />
          <security mode="None">
          </security>
      </binding>
  </wsHttpBinding>
</bindings>
<behaviors>
  <serviceBehaviors>
    <behavior name="digiPM.Service.Behavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
      <dataContractSerializer maxItemsInObjectGraph="2147483647" />
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="customObjectQuota">
      <dataContractSerializer maxItemsInObjectGraph="2147483646"/>
    </behavior>
  </endpointBehaviors>
</behaviors>
<services>
  <service behaviorConfiguration="digiPM.Service.Behavior"
    name="digiPM.Service.AddressCrudService">
    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_Services"
                name="AddressCrudServiceEndPoint" bindingNamespace="urn:Dawliasoft.Sculpture"  contract="digiPM.Services.Contracts.IAddressCrudService" behaviorConfiguration="customObjectQuota" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"  behaviorConfiguration="customObjectQuota" />
  </service>
 <!--<more services defined with same configuration as above..>-->
  </services>

</system.serviceModel>

然而,这并没有帮助。请注意,在APP.CONFIG中引用的服务并不是我有问题的服务。

我还尝试了以下方法:

  • 将这些属性添加到服务实现中:[DataContract(IsReference=true)], [ServiceBehavior(AddressFilterMode = AddressFilterMode.]任意,MaxItemsInObjectGraph = 2147483646)]

  • 写了一个自定义的DataContractSerializerOperationBehavior类来设置maximumobjectsinggraph和IsReference行为。还添加了自定义属性以将其应用于服务实现。为了混乱起见,我没有发布代码,但如果有人认为这是有益的,可以添加它。

想法吗?想法吗?我该何去何从?

提前感谢!

配置下面的值为我解决了这个问题。

客户端配置:

<system.serviceModel>
<bindings>
<basicHttpBinding>
  <binding name="BasicHttpBinding_IManagementService" closeTimeout="00:01:00"
    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
    maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647"
    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
    useDefaultWebProxy="true">
    <readerQuotas maxDepth="128" maxStringContentLength="2147483647"
      maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
    <security mode="None">
      <transport clientCredentialType="None" proxyCredentialType="None"
        realm="" />
      <message clientCredentialType="UserName" algorithmSuite="Default" />
    </security>
  </binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://XXXX/ManagementService.svc"
  binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IManagementService"
  contract="ManagementServiceReference.IManagementService"
  name="BasicHttpBinding_IManagementService" behaviorConfiguration="ManagementServiceBehaviour"/>
</client>
<behaviors>
<endpointBehaviors>
  <behavior name="ManagementServiceBehaviour">
    <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
  </behavior>
</endpointBehaviors>
</behaviors>

服务器配置:

<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<behaviors>
<serviceBehaviors>
  <behavior name="ManagementServiceBehaviour">
    <serviceDebug includeExceptionDetailInFaults="true" />
    <serviceMetadata httpGetEnabled="true" />
    <dataContractSerializer ignoreExtensionDataObject="false" maxItemsInObjectGraph="2147483646" />
  </behavior>
  <behavior name="">
    <serviceMetadata httpGetEnabled="true" />
    <serviceDebug includeExceptionDetailInFaults="false" />
  </behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
  <binding name="BasicHttpBinding" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" closeTimeout="01:50:00" openTimeout="01:50:00" sendTimeout="01:50:00" receiveTimeout="01:50:00" >
    <readerQuotas maxDepth="128" maxStringContentLength="8388608" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
  </binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="ManagementServiceBehaviour" name="BusinessLogic.Facade.EntityFacade.Services.ManagementService">
  <endpoint binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding" contract="BusinessLogic.Facade.EntityFacade.Contracts.IManagementService">
    <identity>
      <dns value="" />
    </identity>
  </endpoint>
</service>
</services>
</system.serviceModel>

您是否也尝试过提高缓冲区和最大接收消息大小?

maxBufferSize="6553600" maxBufferPoolSize="52428800" maxReceivedMessageSize="6553600"

我刚刚意识到你的WPF配置文件不正确。所以,我删除了我所有的评论,因为他们假设一个有效的WCF配置。您的WPF配置文件不正确…应该写"客户"而不是"服务"…您是否在Visual Studio中使用"添加服务引用"?如果是,它应该已经为您创建了正确的配置文件。

否则,请参考MSDN以获取WPF项目中客户端配置文件的正确格式。

小心"dataContractSerializer"元素。在我的情况下,我得到了提到的错误,直到我把这个元素作为父元素"行为"的第一项。至少在客户端是这样。

您正在返回一个大小大于65536的泛型列表或数组。在查询中,使用select top 60000或不添加超过60k个元素将解决您的问题。

相关内容

  • 没有找到相关文章

最新更新