2012-10-02 25 views
1

的Web服務時,我有一個是本地託管的WCF服務。我的web.config看起來是這樣的:如果我通過在不到8K的文本錯誤調用帶有大量數據

<system.serviceModel> 
<bindings> 
    <basicHttpBinding> 
    <binding name="BasicHttpBinding_INavigationService" closeTimeout="00:01:00" 
     openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
     allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
     maxBufferSize="6553600" maxBufferPoolSize="5242880" maxReceivedMessageSize="6553600" 
     messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" 
     useDefaultWebProxy="true"> 
     <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" 
     maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> 
     <security mode="None"> 
     <transport clientCredentialType="None" proxyCredentialType="None" 
      realm="" /> 
     <message clientCredentialType="UserName" algorithmSuite="Default" /> 
     </security> 
    </binding>  
    </basicHttpBinding> 
</bindings> 
<client> 
    <endpoint address="http://localhost/WebServices/NavigationService.svc/" 
    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_INavigationService" 
    contract="NavigationService.INavigationService" name="BasicHttpBinding_INavigationService" /> 
</client> 
</system.serviceModel> 

我的服務工作正常。任何更多,我得到以下錯誤:

Sys.WebForms.PageRequestManagerServerErrorException: The formatter threw an exception while trying to deserialize the message: Error in deserializing body of request message for operation 'UpdateSiteMap'. The maximum string content length quota (8192) has been exceeded while reading XML data. This quota may be increased by changing the MaxStringContentLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader. Line 75, position 166 

有人可以告訴我如何增加文本配額?正如你所看到的,我將它設置爲最大整數大小。

編輯

蒂姆的建議後,這裏是我的新Web.Config文件:

<system.serviceModel> 
<bindings> 
    <basicHttpBinding> 
    <binding closeTimeout="00:01:00" 
     openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
     allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
     maxBufferSize="6553600" maxBufferPoolSize="5242880" maxReceivedMessageSize="6553600" 
     messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" 
     useDefaultWebProxy="true"> 
     <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" 
     maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> 
     <security mode="None"> 
     <transport clientCredentialType="None" proxyCredentialType="None" 
      realm="" /> 
     <message clientCredentialType="UserName" algorithmSuite="Default" /> 
     </security> 
    </binding>  
    </basicHttpBinding> 
</bindings> 
<client> 
    <endpoint address="http://localhost/WebServices/NavigationService.svc/" 
    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_INavigationService" 
    contract="NavigationService.INavigationService" name="BasicHttpBinding_INavigationService" /> 
</client> 
<services> 
    <service name="Navigation.INavigationService"> 

    <endpoint address="" 
       binding="basicHttpBinding" 
       bindingConfiguration="BasicHttpBinding_INavigationService" 
       contract="NavigationService.INavigationService" /> 

    </service> 
</services> 

+0

發表您的服務配置文件 - 它看起來像你需要增加值在那裏,不是你的客戶端上。 – Tim

+0

你正在顯示客戶端的配置,你的服務器端是否也有maxBuffer,contentLength,messageSize等相同的配置? – loopedcode

+0

夥計們,我的服務和我的客戶端都在相同的IIS應用程序下運行,所以web.config對於兩者都是相同的。 – Icemanind

回答

1

基於錯誤的信息和你的問題的描述,您需要確保您的服務具有相同的設置,請參閱相同的bindingConfigendpoint元素的定義綁定:

<system.serviceModel> 
    <services> 
    <service name="Navigation.INavigationService"> 
     <endpoint address="" 
       binding="basicHttpBinding" 
       bindingConfiguration="BasicHttpBinding_INavigationService" 
       contract="NavigationService.INavigationService" /> 
    </service> 
    </services> 
</system.serviceModel> 

如果你使用.NET 4.0,並沒有指定的服務元素,那麼你使用的是默認的終結點和默認綁定(這意味着你的僅限於8192 maxStringContentLength)。解決此問題的最簡單方法是從配置的綁定部分中刪除name屬性 - 然後,.NET將使用您的定義作爲默認綁定。例如:

<binding closeTimeout="00:01:00" .... 

注意沒有name屬性設置。

您可能需要使用選項1在這種情況下,或創建一個類似的綁定定義沒有名字,因爲我不是100%肯定默認綁定用於客戶端;他們肯定是爲了這項服務。

上默認綁定和端點的更多信息,請參見A Developer's Introduction to Windows Communication Foundation 4

基於編輯

附加應答試試這個:

<client> 
    <endpoint address="http://localhost/WebServices/NavigationService.svc/" 
      binding="basicHttpBinding" 
      contract="NavigationService.INavigationService" 
      name="BasicHttpBinding_INavigationService" /> 
</client> 

刪除<services>部分作爲默認端點機制的WCF 4.0將處理爲你,從刪除bindingConfiguration屬性客戶端端點。

+0

我刪除了名稱標籤並添加了標籤。我需要在某處指定最大尺寸嗎? – Icemanind

+0

只要綁定(沒有名稱屬性)具有更大的大小定義,你應該沒問題。 – Tim

+0

呃!同樣的確切錯誤。你有什麼建議蒂姆? – Icemanind

相關問題