2011-01-29 96 views
4

我們正在嘗試將大型XML字符串發送到WCF服務的方法和我們得到的錯誤WCF配置maxStringContentLength似乎並不奏效

最大字符串的內容長度 配額(8192 )已被超出,而 讀取XML數據。

錯誤提示增加maxstringcontentlength儘管我們不確定我們是否應該在客戶端或服務器端或兩者都執行此操作。我們嘗試了兩種方式,但我們似乎仍然得到了錯誤。我將在下面發佈客戶端和服務配置。我假設他們中的一個或兩個都有問題,阻止了它的工作。

有什麼建議嗎?

客戶:

<system.serviceModel> 
    <bindings> 
     <basicHttpBinding> 
      <binding name="BasicHttpBinding_ITESTService" 
       closeTimeout="00:01:00" openTimeout="00:01:00" 
       receiveTimeout="00:10:00" sendTimeout="00:01:00" 
       allowCookies="false" bypassProxyOnLocal="false" 
       hostNameComparisonMode="StrongWildcard" 
       maxBufferSize="65536" maxBufferPoolSize="524288" 
       maxReceivedMessageSize="65536" 
       messageEncoding="Text" textEncoding="utf-8" 
       transferMode="Buffered" useDefaultWebProxy="true"> 
       <readerQuotas maxDepth="32" maxStringContentLength="2147483647" 
        maxArrayLength="2147483647" maxBytesPerRead="4096" 
        maxNameTableCharCount="2147483647" /> 
       <security mode="None" /> 
      </binding> 
     </basicHttpBinding> 
    </bindings> 
    <client> 
     <endpoint name="BasicHttpBinding_ITESTService" 
      address="http://localhost/TESTService.svc" 
      binding="basicHttpBinding" 
      bindingConfiguration="BasicHttpBinding_ITESTService" 
      contract="TESTService.ITESTService" /> 
    </client> 
</system.serviceModel> 

服務器:

<system.serviceModel> 
    <bindings> 
     <basicHttpBinding> 
      <binding 
       name="BasicHttpBinding_Service1" 
       maxBufferSize="2147483647" 
       maxReceivedMessageSize="2147483647"> 
      <readerQuotas maxDepth="32" 
       maxStringContentLength="2147483647" maxArrayLength="2147483647" 
       maxBytesPerRead="4096" maxNameTableCharCount="2147483647" /> 
      <security mode="None" /> 
     </binding> 
     </basicHttpBinding> 
    </bindings> 
    <services> 
     <service name="TESTService"> 
      <endpoint name="BasicHttpBinding_Service1" 
       address="http://localhost/TESTService.svc" 
       binding="basicHttpBinding" 
       bindingConfiguration="BasicHttpBinding_Service1" 
       contract="ITESTService" /> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior> 
      <serviceMetadata httpGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="false" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 

回答

0

thread詳細解釋瞭如何正確爲了改變MaxStringContentLength指定的服務器和客戶端的綁定設置。

這個其他thread也提供了一個清晰和高效的答案,使用readerQuotas。

2

嘗試添加'默認'綁定(沒有指定任何名稱)。 將readerQuota設置添加到此綁定。

然後,您甚至可以從您實際使用的命名綁定中刪除readerQuota設置。

這爲我工作(雖然我不知道爲什麼在正確的命名結合readerQuotas通過WCF忽略)

1

「默認」綁定選項爲我工作。我試圖在名爲WebHttpBinding中自定義maxStringContentLength值,但由於某種原因它沒有被WCF拾起。最後我跟隨了D.Tiemstra的工作,然後開始工作。

<webHttpBinding>   
    <binding maxReceivedMessageSize="2147483647" > 
     <readerQuotas maxDepth="2147483647" 
     maxStringContentLength="2147483647" 
     maxArrayLength="2147483647" 
     maxBytesPerRead="2147483647" 
     maxNameTableCharCount="2147483647" /> 
    </binding> 
    </webHttpBinding> 
+0

我不知道這些最大值是正確的,我會去的: `MAXBUFFERSIZE = 2147483647, MaxBufferPoolSize = 524288, MaxReceivedMessageSize = 2147483647, ReaderQuotas = new XmlDictionaryReaderQuotas { MaxDepth = 32, MaxStringContentLength = 8192, MaxArrayLength = 16384, MaxBytesPerRead = 4096, MaxNameTableCharCount = 1638 } – DanielV 2017-09-28 09:08:05

1

我會用這個值作爲WCF配置(編程):

Security = { Mode = SecurityMode.None}, 
CloseTimeout = TimeSpan.MaxValue, 
OpenTimeout = TimeSpan.MaxValue, 
SendTimeout = TimeSpan.FromMinutes(5), 
ReceiveTimeout = TimeSpan.FromMinutes(5), 
MaxBufferSize = 2147483647, 
MaxBufferPoolSize = 524288, 
MaxReceivedMessageSize = 2147483647, 
ReaderQuotas = new XmlDictionaryReaderQuotas 
{ 
    MaxDepth = 32, 
    MaxStringContentLength = 8192, 
    MaxArrayLength = 16384, 
    MaxBytesPerRead = 4096, 
    MaxNameTableCharCount =1638 
}