2009-08-27 105 views
15

讀我有一個WCF服務下面的服務器端的app.config:WCF maxReceivedMessageSize不是從配置

<system.serviceModel> 
    <bindings> 
     <wsHttpBinding> 
     <binding name="default" maxReceivedMessageSize="5000000"> 
      <readerQuotas maxStringContentLength="5000000" maxArrayLength="5000000" /> 
     </binding> 
     </wsHttpBinding> 
    </bindings> 
    <services> 
     <service behaviorConfiguration="Core.TOAService.Service1Behavior" 
     name="Core.TOAService.TOAService"> 
     <endpoint address="" binding="wsHttpBinding" contract="Core.TOAService.ITOAService"> 
      <identity> 
      <dns value="localhost" /> 
      </identity> 
     </endpoint> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
     <host> 
      <baseAddresses> 
      <add baseAddress="http://localhost:8732/Design_Time_Addresses/Core.TOAService/TOAService/" /> 
      </baseAddresses> 
     </host> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="Core.TOAService.Service1Behavior"> 
      <!-- 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> 
    </system.serviceModel> 

當我試圖通過這個服務一個相當大的文件(僅〜250KB),我得到記錄在文件svclog一個例外:

的最大消息大小配額 傳入消息(65536)一直 超出。要增加配額,請使用 MaxReceivedMessageSize屬性 上適當的綁定元素。

正如你可以在配置的頂部的結合部看,我已經嘗試了maxReceivedMessageSize設置〜5000000,但該服務仍然認爲它設置爲默認的65536任何想法,什麼是錯的或者哪個是「合適的」綁定元素?

回答

27

還有更多設置:-)嘗試<binding>標記上的「maxBufferPoolSize」和「maxBufferSize」。

但是最大的問題是:你的端點確實不是引用那個綁定配置!

<endpoint address="" 
      binding="wsHttpBinding" contract="Core.TOAService.ITOAService"> 

您需要添加一個引用它,因此它得到有用的 - 只是稱其爲「默認」不工作.....

<endpoint address="" 
      binding="wsHttpBinding" 
      bindingConfiguration="default" 
      contract="Core.TOAService.ITOAService"> 

你提前你的時間;-)在WCF 4中(使用.NET 4.0 - 2009年的某個時候),您將能夠定義「缺省綁定配置」而無需明確命名和引用它們 - 但現在,您需要創建一個鏈接在您的端點和其綁定以及您擁有的任何綁定(或行爲)配置之間!

Marc

+0

是的,你必須引用綁定配置。 緩衝區更改可能不是必需的。 – 2009-08-27 20:50:43

+0

從未很清楚是否真的需要三種緩衝區更改中的哪一種 - 它有助於嘗試並查看。關於如何調整這些設置,真的沒有好的,全面的文檔和解釋,不幸的是...... – 2009-08-27 20:51:52

+0

Doh,爲我使用VS2010構建3.5服務提供了服務!非常感謝,這是固定的。 – 2009-08-27 21:01:45

1

有幾個地方需要設置大小。在你的情況下,我認爲你需要添加讀取配額。這裏有一個例子:

<basicHttpBinding> 
    <binding name="httpBasicBinding_Service" closeTimeout="00:03:00" 
     openTimeout="00:03:00" receiveTimeout="00:10:00" sendTimeout="00:03:00" 
     maxBufferSize="2000001" 
     maxBufferPoolSize="2000001" maxReceivedMessageSize="2000001"> 
     <readerQuotas maxDepth="2000001" maxStringContentLength="2000001" 
     maxArrayLength="2000001" maxBytesPerRead="2000001" maxNameTableCharCount="2000001" /> 
    </binding> 
    </basicHttpBinding> 
15

如果您在使用WCF測試客戶端仍然得到此錯誤消息,這是因爲客戶端有一個單獨的MAXBUFFERSIZE設置。

要解決的問題:

  1. 右鍵單擊配置文件節點在樹的底部
  2. 選擇編輯與SvcConfigEditor

名單將出現可編輯的設置,包括MaxBufferSize。

注:自動生成的代理客戶也默認設置MAXBUFFERSIZE爲65536。

+1

好抓!這解決了我的問題... – 2012-01-04 12:23:39

+0

THANK YOUUUU !!! – RoeeK 2013-05-19 20:22:46

相關問題