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



2022年2月28日 星期一

[除錯] 無法建立 SSL/TLS 的安全通道

問題:

無法建立 SSL/TLS 的安全通道

收到來自傳輸資料流的未預期 EOF 或 0 個位元組


參考:

SecurityProtocolType 列舉

CA5386:避免將 SecurityProtocolType 值寫入程式碼


HttpWebRequest GetResponse()出現"要求已經中止: 無法建立 SSL/TLS 的安全通道"錯誤

[C#] 無法建立 SSL/TLS 的安全通道。解決方法

[VB.NET]加入HTTPS的服務參考遇到的問題

【原創】C# API 未能創建 SSL/TLS 安全通道 問題解決

要求已經中止: 無法建立 SSL/TLS 的安全通道。

HttpWebRequest GetResponse()出現"要求已經中止: 無法建立 SSL/TLS 的安全通道"錯誤

【茶包射手日記】.NET 3.5 TLS 1.2 踩雷記

.NET Framework 3.5 and TLS 1.2


解決C#呼叫有ssl憑證問題的網站出現遠端憑證是無效的錯誤問題

呼叫有ssl憑證問題的網站出現遠端憑證是無效的錯誤問題

ServicePointManager.ServerCertificateValidationCallback += RemoteCertificateValidate;

private static bool RemoteCertificateValidate(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors error)

{

    //// trust any certificate!!!

    //System.Console.WriteLine("Warning, trust any certificate");

    //return true;

            

    if (error == SslPolicyErrors.None)

    {

        return true;

    }

    var request = sender as HttpWebRequest;

    if (request != null)

    {

        var result = (request.RequestUri.Host == "11x.x.x.x" || request.RequestUri.Host == "192.16x.x.x");

        return result;

    }

    return false; 

}

CA5359: Do not disable certificate validation

AuthenticationException: Authentication failed, see inner exception. Win32Exception: 接收到的訊息超出預期或格式不正確。WebException: 要求已經中止: 無法建立 SSL/TLS 的安全通道。

System.Net.WebException: 要求已經中止: 無法建立 SSL/TLS 的安全通道 錯誤的另一種可能性2018-10-19



公開WebService:

政府資料開放平臺資料集清單

ListPriceWebService_NaturalGas

ListPriceWebService


解決:Winform .net 3.5

ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;


//動態調用webservices Url

string url = "https://vipmember.tmtd.cpc.com.tw/OpenData/ListPriceWebService.asmx";


//無參數調用

object result1 = WebServiceHelper.InvokeWebService(url, "getCPCAviationFuelListPrice", null);          dataGridView1.DataSource = ((DataSet)result1).Tables[0];