WCF:讀取 XML 數據時,超出最大字符串內容長度配額 (8192)。通過更改在創建 XML 讀取器時所使用的 XmlDictionaryReaderQuotas 對象的 MaxStringContentLength 屬性,可增加此配額。


使用WCF傳輸大數據時,我們都會碰到如題中出現的錯誤信息,出現這個問題是因為WCF本身的安全機制導致的,限制了客戶端與服務器資源傳輸大小,那我們如何還解決這個問題呢?

針對這個問題,我們要分發送、接受兩個方面來解決。

發送大數據:在WCF服務端解決

                 NetTcpBinding binding =  new NetTcpBinding();

      binding.MaxReceivedMessageSize= 2147483647(更改這個數字) ;

接受大數據:在WCF客戶端解決

      NetTcpBinding binding =  new NetTcpBinding();

      binding.ReaderQuotas = new XmlDictionaryReaderQuotas() { MaxStringContentLength = 2147483647(更改這個數字) };


我們即可以使用如上述通過代碼配置,我們同樣也可以使用配置文件進行配置(在binding節中)。

public static System.ServiceModel.BasicHttpBinding Binding()
        {
            //讀取 XML 數據時,超出最大字符串內容長度配額 (8192)。
            System.ServiceModel.BasicHttpBinding bing = new System.ServiceModel.BasicHttpBinding();
            bing.ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas() { MaxStringContentLength = 2147483647 }; //(更改這個數字) 
            return bing;
        }

 

public static API.iClient api = new API.iClient(Binding(), new System.ServiceModel.EndpointAddress("http://192.168.1.11:4417/WebService.svc"));  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM