代码之家  ›  专栏  ›  技术社区  ›  Daniel Gee

InnerException消息为“对象图中可序列化或反序列化的最大项数为”65536“。

  •  6
  • Daniel Gee  · 技术社区  · 8 年前

    我可以看到这个问题已经被问了好几次了,但是他们都是关于WCF的。搜索了一段时间后,我无法找到此错误的解决方案。

    我有一个WinForms应用程序,可以从web服务中提取数据。web服务是用WebForms/asp编写的。网

    连接到web服务的代码是:

    Dim _DownloadStock As srShopDownload.shop_downloadsSoapClient
    Dim binding As New STKBinding("STKBinder")
    NewEndPoint = New EndpointAddress("https://www.example.com/web_services/downloads.asmx")
                _DownloadStock = New srShopDownload.shop_downloadsSoapClient(binding._Binder, NewEndPoint)
    _StockcodesList = _DownloadStock.GetStockcodes
    

    我的活页夹代码是

    Public Sub New(ByVal BinderName As String)
    
        _Binder = New BasicHttpBinding()
        _Binder.Name = BinderName
    
        _Binder.CloseTimeout = TimeSpan.FromMinutes(1)
        _Binder.OpenTimeout = TimeSpan.FromMinutes(1)
        _Binder.ReceiveTimeout = TimeSpan.FromMinutes(10)
        _Binder.SendTimeout = TimeSpan.FromMinutes(1)
        _Binder.AllowCookies = False
        _Binder.BypassProxyOnLocal = False
        _Binder.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard
    
        _Binder.MaxBufferSize = 100000000
        _Binder.MaxBufferPoolSize = 12000000
        _Binder.MaxReceivedMessageSize = 100000000
    
        _Binder.MessageEncoding = WSMessageEncoding.Text
        _Binder.TextEncoding = System.Text.Encoding.UTF8
        _Binder.TransferMode = TransferMode.Streamed
        _Binder.UseDefaultWebProxy = True
    
        _Binder.ReaderQuotas.MaxDepth = 2147483647
        _Binder.ReaderQuotas.MaxStringContentLength = 2147483647
        _Binder.ReaderQuotas.MaxArrayLength = 2147483647
        _Binder.ReaderQuotas.MaxBytesPerRead = 2147483647
        _Binder.ReaderQuotas.MaxNameTableCharCount = 2147483647
    
        _Binder.Security.Transport.ClientCredentialType = HttpClientCredentialType.None
        _Binder.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None
        _Binder.Security.Transport.Realm = ""
    
        _Binder.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName
        _Binder.Security.Message.AlgorithmSuite = Security.SecurityAlgorithmSuite.Default
        _Binder.Security.Mode = BasicHttpSecurityMode.Transport
    
    End Sub
    

    在web服务方面,它只是一个基本功能:

    <WebMethod()>
    Public Function GetStockcodes() As List(Of Stockcodes)
    
        Return GetStockcodes()
    
    End Function
    

    我已经看到了应该在客户端和服务器上更改ServiceBehavior的答案,但我不知道如果不使用WCF,该怎么做。

    1 回复  |  直到 8 年前
        1
  •  0
  •   Daniel Gee    7 年前

    我找到了一个解决方法,只是放在这里,以防有人提出同样的问题。

    1. 在电脑上打开此文件夹。它是。NET Framework文件夹:%windir%\Microsoft。净额\

    2. 在此目录中,您应该看到文件夹:Framework和Framework64(在64位环境中)。这两个文件夹都包含几个具有特定名称的文件夹。NET版本(例如v2.0.50727)。您需要浏览每个文件夹,看看它是否包含CONFIG目录和名为machine的文件。配置。(或者只搜索machine.config)

    3. 打开以编辑每台机器。配置文件和系统下的。serviceModel节点添加以下子节点:

    <commonBehaviors>
        <endpointBehaviors>
            <dataContractSerializer maxItemsInObjectGraph="2147483647" />
        </endpointBehaviors>
        <serviceBehaviors>
            <dataContractSerializer maxItemsInObjectGraph="2147483647" />
        </serviceBehaviors>
    </commonBehaviors> 
    
    1. 编辑后,应如下所示:

    <system.serviceMode>
        (...)
        <extensions>
            (...)
        </extensions>
        <client>
            (...)
        </client>
        <commonBehaviors>
              <endpointBehaviors>
                  <dataContractSerializer maxItemsInObjectGraph="2147483647" />
              </endpointBehaviors>
              <serviceBehaviors>
                  <dataContractSerializer maxItemsInObjectGraph="2147483647" />
              </serviceBehaviors>
        </commonBehaviors> 
        (...)
    </system.serviceModel>
    
    1. 如果系统。配置文件中缺少serviceModel节点,您需要手动创建此节点。

    2. 重新启动应用程序。如果电脑仍然无法工作,您可能需要重新启动电脑。

    我在这里找到了解决方案 link .只要把答案放在这里,以防将来这一页翻下去。