2022年3月3日 星期四

[除錯] 在建立 XML 讀取器時變更 XmlDictionaryReaderQuotas 物件上使用的 MaxStringContentLength 屬性

 環境:

Client:
Winform 3.5 framework 


錯誤訊息:

將作業 'sqlClient_DapperGetData_WithoutParams' 的回覆訊息本文還原序列化時發生錯誤。讀取 XML 資料時已經超過最大字串內容長度配額 (8192)。在建立 XML 讀取器時變更 XmlDictionaryReaderQuotas 物件上使用的 MaxStringContentLength 屬性,便可以增加此配額。


解決:

修改客戶端app.config [新增紅色部份]

        <bindings>

            <basicHttpBinding>

                <binding name="BasicHttpBinding_IService1" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" >

                <readerQuotas maxDepth="32" maxStringContentLength="10485760" maxArrayLength="10485760" maxBytesPerRead="10485760" maxNameTableCharCount="10485760"/>

                </binding>

            </basicHttpBinding>

        </bindings>


參考:

读取XML数据时,已超过最大字符串内容长度配额(8192)。可以通过更改创建XML阅读器时使用的

VS WCF輸傳限制

BasicHttpBinding.ReaderQuotas 屬性

<readerQuotas>

屬性

屬性

屬性

描述

maxArrayLength

正整數,指定 Windows Communication Foundation (WCF) 接收自用戶端允許的資料陣列長度上限。 預設值為 16384。

maxBytesPerRead

正整數,指定允許每個讀取傳回的位元組上限。 預設值為 4096。

maxDepth

正整數,指定允許每個讀取其巢狀節點深度的上限。 預設值為 32。

maxNameTableCharCount

正整數,指定資料表名稱允許的字元數目上限。 預設值為 16384。

maxStringContentLength

正整數,指定 XML 項目內容中允許的字元數上限。 預設值為 8192。


其它參考:

WCF 傳送大量資料時修改config


[除錯] 請變更物件圖形或增加 MaxItemsInObjectGraph 配額

環境:

Client:
Winform 3.5 framework 


錯誤訊息:

嘗試將訊息還原序列化時,格式子發生例外狀況: 嘗試將參數 http://tempuri.org/:Get鋼管庫存表SqlClientResult 還原序列化時發生錯誤。InnerException 訊息為 '物件圖形中可以序列化或還原序列化的項目數目上限是 '65536'。請變更物件圖形或增加 MaxItemsInObjectGraph 配額。 '。如需詳細資訊,請參閱 InnerException。


解決:

修改客戶端app.config [新增紅色部份]

        <behaviors>

          <endpointBehaviors>

            <behavior name="NewBehavior">

              <dataContractSerializer maxItemsInObjectGraph="2147483647"/>

            </behavior>

          </endpointBehaviors>

        </behaviors>

  

        <bindings>

            <basicHttpBinding>

                <binding name="BasicHttpBinding_IService1" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" />

            </basicHttpBinding>

        </bindings>

        <client>

            <endpoint address="http://localhost:1093/Service1.svc"  binding="basicHttpBinding" behaviorConfiguration="NewBehavior"

                bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1"

                name="BasicHttpBinding_IService1" />

        </client>


參考:

WCF中如何修改MaxItemsInObjectGraph的限制

WCF測試錯誤碼

MaxItemsInObjectGraph

[ASP.NET] WCF 傳輸超過 65536 的資料


其它參考:

解决进行反序列化时出错:。InnerException 消息是“反序列化对象 属于类型 System.String 时出现错误。读取 XML 数据时,超出最大字符串内容长度配额

maxReceivedMessageSize and maxBufferSize in app.config