Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 例外:对象图中可序列化或反序列化的最大项数为';65536';_C#_Visual Studio 2010_Wcf_Serialization_Datacontractserializer - Fatal编程技术网

C# 例外:对象图中可序列化或反序列化的最大项数为';65536';

C# 例外:对象图中可序列化或反序列化的最大项数为';65536';,c#,visual-studio-2010,wcf,serialization,datacontractserializer,C#,Visual Studio 2010,Wcf,Serialization,Datacontractserializer,我查看了其他帖子,但没有找到解决问题的方法 我的服务配置文件: <?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net"/> </configSections>

我查看了其他帖子,但没有找到解决问题的方法

我的服务配置文件:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net"/>
  </configSections>
  <appSettings>
    ...
  </appSettings>
  <log4net>
    ...
  </log4net>
  <system.serviceModel>
    <protocolMapping>
      <add scheme="http" binding="wsDualHttpBinding"/>
    </protocolMapping>
    <services>
      <service name="Service1" behaviorConfiguration="Service1Behavior">
        <endpoint address="" binding="netTcpBinding" contract="IService1" bindingConfiguration="NetTcpBinding_IService1">
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="/mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
      </service>
      <service name="Service2" behaviorConfiguration="Service2Behavior">
        <endpoint address="" binding="wsHttpBinding" contract="IService2" bindingConfiguration="WSHttpBinding_IService2">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <bindings>
      <wsHttpBinding>
        <binding name="WSHttpBinding_IService2" receiveTimeout="00:00:10"
          sendTimeout="00:00:10" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
          useDefaultWebProxy="false">
          <reliableSession ordered="true" inactivityTimeout="00:00:11" />
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
            maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="None" />
        </binding>
      </wsHttpBinding>
      <netTcpBinding>
        <binding name="NetTcpBinding_IService1" receiveTimeout="00:00:20"
          sendTimeout="00:00:20" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
            maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <reliableSession ordered="true" inactivityTimeout="00:00:11" />
          <security mode="None" />
        </binding>
      </netTcpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="Service1Behavior">
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
          <serviceMetadata httpGetEnabled="False"/>

          <serviceDebug includeExceptionDetailInFaults="True"/>
          <serviceThrottling maxConcurrentCalls="100"
                    maxConcurrentInstances="100"
                    maxConcurrentSessions="100" />
        </behavior>
        <behavior name="Service2Behavior">
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
          <serviceMetadata httpGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="True"/>
          <serviceThrottling maxConcurrentCalls="100"
                    maxConcurrentInstances="100"
                    maxConcurrentSessions="100"  />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
  <connectionStrings>
    ...
  </connectionStrings>
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel" switchValue="Error,ActivityTracing"
        propagateActivity="true">
        <listeners>
          ...
        </listeners>
      </source>
    </sources>
  </system.diagnostics>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
</configuration>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <configSections>
        ...
    </configSections>
    <system.serviceModel>
        <bindings>
            <netTcpBinding>
                <binding name="NetTcpBinding_IService1" closeTimeout="00:00:15"
                    openTimeout="00:00:15" receiveTimeout="00:00:40" sendTimeout="00:00:40"
                    transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
                    hostNameComparisonMode="StrongWildcard" listenBacklog="10"
                    maxBufferPoolSize="2147483647" maxBufferSize="2147483647"
                    maxConnections="10" maxReceivedMessageSize="2147483647">
                    <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                        maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
                    <reliableSession ordered="true" inactivityTimeout="00:10:00"
                        enabled="false" />
                    <security mode="None">
                        <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
                        <message clientCredentialType="Windows" />
                    </security>
                </binding>
            </netTcpBinding>
            <wsHttpBinding>
                <binding name="WSHttpBinding_IService2" closeTimeout="00:00:15"
                    openTimeout="00:00:15" receiveTimeout="00:00:25" sendTimeout="00:00:15"
                    bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
                    messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="false">
                    <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                        maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
                    <reliableSession ordered="true" inactivityTimeout="00:00:11" />
                    <security mode="None">
                        <transport realm="" />
                        <message clientCredentialType="Windows" negotiateServiceCredential="true" />
                    </security>
                </binding>
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://.../Design_Time_Addresses/Service2/"
                binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService2"
                contract="Service2Reference.IService2"
                name="WSHttpBinding_IService2"  behaviorConfiguration="serviceBehaviorConfiguration">
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>
            <endpoint address="net.tcp://.../Design_Time_Addresses/Service1/"
                binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IService1"
                contract="Service1Reference.IService1" name="NetTcpBinding_IService1"
                behaviorConfiguration="serviceBehaviorConfiguration">
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>
        </client>
      <behaviors>
        <endpointBehaviors>
          <behavior name="serviceBehaviorConfiguration">
            <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
          </behavior>
        </endpointBehaviors>
      </behaviors>
    </system.serviceModel>
    <userSettings>
        ...
    </userSettings>

</configuration>

Is似乎忽略了两个
App.config
文件中的
。为什么?

在客户端,请参见标记为
**
的三行:

    <client>
        <endpoint address="http://.../Design_Time_Addresses/Service2/"
****        behaviorConfiguration="foo"
            binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService2"
            contract="Service2Reference.IService2"
            name="WSHttpBinding_IService2">
            <identity>
                <dns value="localhost" />
            </identity>
        </endpoint>
        <endpoint address="net.tcp://.../Design_Time_Addresses/Service1/"
****        behaviorConfiguration="foo"
            binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IService1"
            contract="Service1Reference.IService1" name="NetTcpBinding_IService1">
            <identity>
                <dns value="localhost" />
            </identity>
        </endpoint>
    </client>
  <behaviors>
    <endpointBehaviors>
****  <behavior name="foo">
        <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
      </behavior>
    </endpointBehaviors>
  </behaviors>

****  
添加到配置中

<behaviors> 
    <endpointBehaviors> 
        <behavior name="Behaviors.EndpointBehavior"> 
            <dataContractSerializer maxItemsInObjectGraph="2147483647" /> 
        </behavior> 
    </endpointBehaviors> 
</behaviors
(来源:)


我认为您还必须修改服务器端定义和客户端端点。

我通过在C代码中添加行为解决了这个问题


问题可能是因为使用了带有
InstanceContext
Binding
EndpointAddress
ServiceClient
构造函数,所以忽略了
app.config
中的行为。

是的,我也尝试了这个方法。还是没有working@Saint嗯,好,;右-需要澄清的是:当这个中断时,哪一端是序列化?客户或服务器?服务器部分semms正常。客户端是broken@Saint六羟甲基三聚氰胺六甲醚。。。这很烦人;除非我疯了,否则上面的问题应该解决了it@Saint是的,那是正常的是的,我也试过这个。仍然不工作:(在重建后尝试重新生成客户端配置,不要忘记在服务器端应用此值!代码隐藏版本对我有效;接受的答案仅在使用双工端点时有效。@Cybermaxs Betclic否,它不重复。我使用的是“添加服务引用”在Visual Studio中,因此我的配置文件是正确的。请您解释一下此代码应该放在哪里?是在实例化应用程序时?还是在每次连接之前?谢谢。我不完全理解您描述的构造函数问题。
<behaviors> 
    <endpointBehaviors> 
        <behavior name="Behaviors.EndpointBehavior"> 
            <dataContractSerializer maxItemsInObjectGraph="2147483647" /> 
        </behavior> 
    </endpointBehaviors> 
</behaviors
<client> 
    <endpoint address=http://localhost:9997/Services/MyService 
        behaviorConfiguration="Behaviors.EndpointBehavior" 
        binding="wsHttpBinding" bindingConfiguration="WSHTTPBinding.Configuration.Client" 
        contract="IAppointments" name="Client.EndpointConfiguration" /> 
</client>
foreach ( var operation in channelFactory.Endpoint.Contract.Operations )   
{   
    var behavior = operation.Behaviors.Find() as DataContractSerializerOperationBehavior;   
    if ( behavior != null )   
    {   
        behavior.MaxItemsInObjectGraph = 2147483647;       
    }   
} 
client.Endpoint.Behaviors.Remove(typeof(CallbackBehaviorAttribute));
client.Endpoint.Behaviors.Add(new CallbackBehaviorAttribute() { MaxItemsInObjectGraph = 2147483647 });