WCF错误"可序列化或反序列化对象图中的最大项目数量是'65536'"序列化、图中、对象、数量

2023-09-02 21:08:22 作者:痞

我接到一个电话WCF以下错误:

I am receiving the following error on a WCF call:

这可以被序列化或反序列化中的最大项目数量   对象图是65536

Maximum number of items that can be serialized or deserialized in an object graph is '65536'

我读过一吨的论坛帖子,其中许多人提修改的app.config和web.config中指定新的行为,允许更大的对象图。我已经做到了,这就是我在这些文件:

I've read a ton of forum posts and many of them mention modifying the app.config and web.config to specify new behavior to allow larger object graphs. I've done that and this is what I have in those files:

的app.config在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 -->

web.config中的服务项目:

<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中引用的服务不服务我有问题。

This, however, hasn't helped. Note that the services referenced in the APP.CONFIG are not the services I am having issues with.

我也试过如下:

添加这些属性的服务实现:[DataContract(IsReference = TRUE)],[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any,MaxItemsInObjectGraph = 2147483646)]

added these attributes to the service implementation: [DataContract(IsReference=true)], [ServiceBehavior(AddressFilterMode = AddressFilterMode.Any, MaxItemsInObjectGraph = 2147483646)]

写道,设置MaximumObjectsInGraph和IsReference行为的自定义DataContractSerializerOperationBehavior类。还增加了自定义属性应用该服务实现。为了杂乱的,我没有贴code,但如果有人认为这将是有益的可以添加它。

wrote a custom DataContractSerializerOperationBehavior class that set MaximumObjectsInGraph and IsReference behavior. Also added custom Attribute to apply this the service implementations. For the sake of clutter, I didn't post the code, but can add it if anyone thinks it would be beneficial.

思考?想法?我在哪里何去何从?

Thoughts? Ideas? Where do I go from here?

在此先感谢!

推荐答案

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

I just realized that your WPF config file is not right. So, I deleted all my comments because they were assuming a valid WCF configuration. Your WPF config file is not right ... it needs to say "Client" instead of service ... Are you using "Add Service Reference" in Visual Studio? if so, it should have created the correct config file for you.

否则,请参阅 MSDN 以正确的格式为您的客户端配置文件的WPF项目。

Otherwise, please refer to MSDN for the correct format for your client config file in your WPF project.

 
精彩推荐
图片推荐