2013-07-10 81 views
0

我做簡單的WCF服務在IIS上 客戶的WinForms運行 服務器端。WCF MaxStringContentLength錯誤

當我試圖大串發送到服務器,我異常有如下:

格式化拋出一個異常,而試圖反序列化 消息:錯誤操作 「CreateFolder」反序列化請求消息的身體。在讀取XML數據時,超過了最大字符串內容長度配額(8192) 。此配額可以增加 改變在 XmlDictionaryReaderQuotas的MaxStringContentLength屬性創建XML讀取器時對象使用。 147 線,位置78

客戶端的app.config:

<configuration> 
    <system.serviceModel> 
    <bindings> 
     <basicHttpBinding> 
     <binding name="BasicHttpBinding_IService1" maxReceivedMessageSize="10000000" > 
      <readerQuotas maxDepth="32" maxStringContentLength="10000000" maxArrayLength="16384" 
        maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
     </binding> 
     </basicHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="http://192.168.15.72:7777/Service1.svc" binding="basicHttpBinding" 
     bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1" 
     name="BasicHttpBinding_IService1" /> 
    </client> 
    </system.serviceModel> 
</configuration> 

服務器Web配置:

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 

    <system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
    </system.web> 
    <system.serviceModel> 
    <bindings> 
     <basicHttpBinding> 
     <binding name="BasicHttpBinding_IService1" maxReceivedMessageSize="10000000" 
     maxBufferSize="10000000" > 
      <readerQuotas maxDepth="32" maxStringContentLength="10000000" maxArrayLength="16384" 
        maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
     </binding> 
     </basicHttpBinding> 
    </bindings> 
    <services> 
     <service name="WCFService"> 
     <endpoint address="" binding="basicHttpBinding" 
      bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1" 
      name="BasicHttpBinding_IService1"> 
     </endpoint> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior> 
      <serviceMetadata httpGetEnabled="true"/> 
      <serviceDebug includeExceptionDetailInFaults="false"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 

    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 
    <appSettings> 
    <add key="PathToSafe" value="D:\Temp"/> 
    </appSettings> 
<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 

</configuration> 

當我在本地主機上運行的服務器IIS它的偉大工程。 任何想法如何解決這個問題?

+2

重複的可能看到這個鏈接在這裏,http://stackoverflow.com/questions/6600057/the-maximum-string-content-更新服務器端配置長度配額8192 - 過氣 - 超過-而讀-X – Bearcat9425

+0

請注意,如果你沒有指定該綁定定義端點(通過'endpoint'元素的'bindingConfiguration'屬性)的變化贏得不會生效。將使用端點指定綁定的默認值。 – Tim

回答

0

檢查maxReceiveMessageSize和MAXBUFFERSIZE

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

他們應該足夠大,讓你的大串+還有什麼是你的消息

2

的結合既適用於客戶端和服務。您正確地修改了客戶端,但您也需要在服務器端進行修改。

客戶端發送請求到服務器 - 服務器正在做反序列化和反序列化時發生的錯誤。一切都指出你沒有綁定(的web.config)

+0

你能告訴我該怎麼配置嗎?我不知道如何操作 – Yury

+0

找到web.config文件。找到「bindings \ basicHttpBinding」部分,並將客戶端的「綁定」節點複製粘貼到服務中找到的匹配節點上。如果你仍然不確定 - 複製/粘貼web.config並更新你的文章,我會發佈一個答案,看起來應該如何... – veljkoz