2012-10-05 57 views
2

好吧,我不知道發生了什麼。我在這裏發現了一堆帖子,並且使用了谷歌搜索,但他們都說幾乎相同的事情:改變客戶端和服務器的maxStringContentLength。我已經完成了更多,但我仍然得到同樣的該死的錯誤。我也嘗試改變最大長度編程,但沒有骰子。在服務器WCF:已超出最大字符串內容長度配額(8192)

Web.config文件:

<system.serviceModel> 
<bindings> 
    <basicHttpBinding> 
    <binding name="BasicHttpBinding_IService1" 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="2147483647" maxReceivedMessageSize="65536" 
     messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" 
     useDefaultWebProxy="true"> 
     <readerQuotas maxDepth="320" maxStringContentLength="2147483647" maxArrayLength="16384" 
     maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
     <security mode="None"> 
     <transport clientCredentialType="None" proxyCredentialType="None" 
      realm="" /> 
     <message clientCredentialType="UserName" algorithmSuite="Default" /> 
     </security> 
    </binding> 
    </basicHttpBinding> 
</bindings> 
<client> 
    <endpoint address="http://localhost:52826/Service1.svc" binding="basicHttpBinding" 
     bindingConfiguration="BasicHttpBinding_IService1" 
     contract="ServiceReference1.IService1" 
     name="BasicHttpBinding_IService1">   
    </endpoint> 
</client> 


<behaviors> 
    <endpointBehaviors> 
    <behavior name="wsServiceBehavior"> 
     <dataContractSerializer maxItemsInObjectGraph="2147483646" /> 
    </behavior> 
    </endpointBehaviors> 

    <serviceBehaviors> 
    <behavior> 
     <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> 
     <serviceMetadata httpGetEnabled="true"/> 
     <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> 
     <serviceDebug includeExceptionDetailInFaults="true"/> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 

,並在客戶端:

<system.serviceModel> 
<bindings> 
    <basicHttpBinding> 
    <binding name="BasicHttpBinding_IService1" 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="16384" 
     maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
     <security mode="None"> 
     <transport clientCredentialType="None" proxyCredentialType="None" 
      realm="" /> 
     <message clientCredentialType="UserName" algorithmSuite="Default" /> 
     </security> 
    </binding> 
    </basicHttpBinding> 
</bindings> 
<client> 
    <endpoint address="http://localhost:52826/Service1.svc" binding="basicHttpBinding" 
    bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1" 
    name="BasicHttpBinding_IService1" /> 
</client> 

我也注意到,當我運行服務。生成的配置文件列出了maxStringContentLength =「8192」。我嘗試關閉「啓動服務時始終重新生成配置文件」選項並直接編輯配置文件以增加最大值,但它仍然無效。

- EDIT-- 看起來該服務實際上並沒有像Eugune提到的那樣提取配置。我添加在:

<services> 
    <service name="Courrier.myService"> 
    <endpoint address="http://localhost:52826/Service1.svc" binding="basicHttpBinding" 
     bindingConfiguration="BasicHttpBinding_IService1" 
    contract="ServiceReference1.IService1"> 
    </endpoint> 
    </service> 
</services> 

但仍然無法正常工作?

回答

3

當我在客戶端看到這個錯誤時,通常意味着該服務引發異常。如果您爲Web服務啓用了顯示錯誤,則例外情況下的堆棧跟蹤可能會輕鬆地吹掉8192字符串限制。

+0

我正在閱讀文本文件中的字符串並將其發送到服務。長度計數是〜11k。當我用字符串代替讀取文件時,一切正常。所以我不認爲有一個錯誤被拋出。 – ygetarts

+2

@ user850237 - 您可以將您讀取文本文件的代碼發佈到字符串中嗎?在代碼中可能會拋出異常,而對字符串進行硬編碼則不會。 – Tim

+0

我真的不這麼認爲。我正在讀取客戶端上的文件,將其轉換爲字符串,然後發送。 ServiceReference1.Service1Client sc = new Service1Client(); TextReader tr = new StreamReader(emailPath); var inputEmail = tr.ReadToEnd(); var emailSend = sc.SendEMail(fromEmailAddress,subject,inputEmail,toEmailAddress,「nothing」,url,true,32,100,100); – ygetarts

1

你確定你確實改變了服務器上的配額嗎?在你的「服務器」配置中,你定義了一個帶有增加配額的BasicHttpBinding_IService1綁定,但是你只能在<客戶端>部分使用它。

+0

我想這可能是它。它沒有出現服務正在拾取我創建的配置,並訴諸默認。我編輯了我原來的問題,添加了我添加到服務器配置文件中的內容,但仍然無法正常工作? – ygetarts

相關問題