2013-04-28 260 views
20

我的設置:在IIS快遞 WCF錯誤 - 最大郵件大小配額傳入消息(65536)已超過

  • WCF服務託管

    • ASP.NET客戶端控制檯應用程序託管
    • 運行Visual Studio.NET 2012在管理模式

    我想從WCF服務返回2個List對象。當我僅返回1個List對象時,我的設置WORKS FINE。但是,當我返回2列表對象時,出現錯誤:

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

    我知道這個問題已經在這個網站和其他網站上被詢問了很多次。我已經嘗試幾乎所有發佈在互聯網上的配置文件的各種組合,但仍然沒有爲我工作。

    客戶端配置:

    <configuration> 
        <system.web> 
         <compilation debug="true" targetFramework="4.0" /> 
         <httpRuntime maxRequestLength="1572864"/> 
        </system.web> 
    
        <system.serviceModel> 
         <client> 
          <endpoint name="basicHttpBinding" 
           address="http://localhost:9502/HCDataService" 
           binding="basicHttpBinding" 
           bindingConfiguration="basicHttpBinding"     
           contract="HC.APP.Common.ServiceContract.IHCServiceContract" 
           behaviorConfiguration="ServiceBehaviour"> 
          </endpoint> 
         </client> 
    
         <bindings> 
          <basicHttpBinding> 
           <binding name="basicHttpBinding" maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647"> 
            <readerQuotas maxDepth="128" maxStringContentLength="2147483647" maxArrayLength="2147483646" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
           </binding> 
          </basicHttpBinding> 
         </bindings> 
    
         <behaviors> 
          <endpointBehaviors> 
           <behavior name="ServiceBehaviour"> 
            <dataContractSerializer maxItemsInObjectGraph="2147483647"/> 
           </behavior> 
          </endpointBehaviors> 
         </behaviors> 
        </system.serviceModel> 
    </configuration> 
    

    服務器配置:

    <configuration> 
        <system.serviceModel> 
         <services> 
          <service name="HC.APP.Server.Service.HCDataService" behaviorConfiguration="ServiceBehaviour"> 
           <host> 
            <baseAddresses> 
             <add baseAddress="http://localhost:9502/HCDataService"/> 
            </baseAddresses> 
           </host> 
    
           <endpoint name="basicHttpBinding" 
            address="http://localhost:9502/HCDataService" 
            binding="basicHttpBinding" 
            bindingConfiguration="basicHttpBinding" 
            contract="HC.APP.Common.ServiceContract.IHCServiceContract"> 
           </endpoint> 
          </service> 
         </services> 
    
         <bindings> 
          <basicHttpBinding> 
           <binding name="basicHttpBinding" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" closeTimeout="01:50:00" openTimeout="01:50:00" sendTimeout="01:50:00" receiveTimeout="01:50:00" > 
            <readerQuotas maxDepth="128" maxStringContentLength="8388608" maxArrayLength="2147483646" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
           </binding> 
          </basicHttpBinding> 
         </bindings> 
    
         <behaviors> 
          <serviceBehaviors> 
           <behavior name="ServiceBehaviour"> 
            <serviceDebug includeExceptionDetailInFaults="true" /> 
            <serviceMetadata httpGetEnabled="true" /> 
            <dataContractSerializer ignoreExtensionDataObject="false" maxItemsInObjectGraph="2147483646" /> 
           </behavior> 
          </serviceBehaviors> 
         </behaviors>  
        </system.serviceModel> 
    </configuration> 
    
  • +0

    我已經更新了Trickery爲其他成員提供的配置文件。這現在是一個工作解決方案。我所做的更多的更改是兩個配置上的maxArrayLength =「2147483646」。是的,端點的命名可以改進。 – 2013-04-28 19:39:24

    +2

    夥計們,我知道這是一個重複的問題,並在我的文章中提到了這一點。我不得不發佈這個問題的原因(也可能是爲什麼存在相同問題的很多變體),因爲WCF配置被壓縮,並且很容易錯過一個MINOR DETAIL。我在本網站以及其他網站上發佈了很多帖子,但無法指出問題所在。它需要一些外部干預來解決問題。所以從技術上講,我的帖子可能聽起來有重複,但它在Trickery指出的小改變中有所不同。 – 2013-04-29 10:57:55

    回答

    33

    那將是因爲你沒有它結合使用服務器上指定。我們來看看您的服務器配置:

    根據<bindings>您正在創建<basicHttpBinding>的綁定配置,並且您將其命名爲name="basicHttpBinding"。另外,您的端點名稱爲<endpoint name="basicHttpBinding" ...>,其綁定爲binding="basicHttpBinding"但是,它不是指您的綁定配置,而是指綁定類型。所以,它實際上使用basicHttpBinding的默認設置。

    要解決這個問題,首先要以不同的方式命名您的端點和綁定配置。例如,<endpoint name="basicEndpoint" ... ><binding name="myBasicBinding" ... >。然後,您需要使用此屬性將您的綁定配置分配給您的端點:bindingConfiguration="myBasicBinding"

    這裏的客戶端配置:

    <system.web> 
        <httpRuntime maxRequestLength="32768"/> 
    </system.web> 
    
    <system.serviceModel> 
        <client> 
         <endpoint name="basicEndpoint" 
          address="http://localhost:9502/HCDataService" 
          binding="basicHttpBinding" 
          bindingConfiguration="myBasicBinding" 
          contract="HC.APP.Common.ServiceContract.IHCServiceContract" 
          behaviorConfiguration="ServiceBehaviour"> 
         </endpoint> 
        </client> 
    
        <bindings> 
         <basicHttpBinding> 
          <binding name="myBasicBinding" maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647"> 
           <readerQuotas maxDepth="128" maxStringContentLength="2147483647" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
          </binding> 
         </basicHttpBinding> 
        </bindings> 
    
        <behaviors> 
         <endpointBehaviors> 
          <behavior name="ServiceBehaviour"> 
           <dataContractSerializer maxItemsInObjectGraph="2147483647"/> 
          </behavior> 
         </endpointBehaviors> 
        </behaviors>  
    </system.serviceModel> 
    

    這裏的服務器配置:

    <system.serviceModel> 
        <services> 
         <service name="HC.APP.Server.Service.HCDataService" behaviorConfiguration="ServiceBehaviour"> 
          <host> 
           <baseAddresses> 
            <add baseAddress="http://localhost:9502/HCDataService"/> 
           </baseAddresses> 
          </host> 
    
          <endpoint name="basicEndpoint" 
           address="http://localhost:9502/HCDataService" 
           binding="basicHttpBinding" 
           bindingConfiguration="myBasicBinding" 
           contract="HC.APP.Common.ServiceContract.IHCServiceContract"> 
          </endpoint> 
         </service> 
        </services> 
    
        <bindings> 
         <basicHttpBinding> 
          <binding name="myBasicBinding" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" closeTimeout="01:50:00" openTimeout="01:50:00" sendTimeout="01:50:00" receiveTimeout="01:50:00" > 
           <readerQuotas maxDepth="128" maxStringContentLength="8388608" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
          </binding> 
         </basicHttpBinding> 
        </bindings> 
    
        <behaviors> 
         <serviceBehaviors> 
          <behavior name="ServiceBehaviour"> 
           <serviceDebug includeExceptionDetailInFaults="true" /> 
           <serviceMetadata httpGetEnabled="true" /> 
           <dataContractSerializer ignoreExtensionDataObject="false" maxItemsInObjectGraph="2147483646" /> 
          </behavior> 
         </serviceBehaviors> 
        </behaviors> 
    </system.serviceModel> 
    

    不要忘記update service reference您的客戶端上,以得到正確的配置。

    +0

    有兩件事:首先,OP需要將此應用於他的**客戶** congif,而不是服務配置。他們在嘗試從服務中接收*而不是發送時遇到此問題。其次,他們確實爲綁定設置了名稱,他們只是沒有明確地將其設置在端點上,正如您所指出的那樣。 – Tim 2013-04-28 18:55:55

    +0

    呃,不。問題是這裏的服務器。客戶端配置只是在添加服務引用時反映服務器的配置。其次,我從來沒有說過OP沒有說出這些東西,只是他以一種令人困惑的方式對它進行了命名,可能他爲什麼首先犯了錯誤,正如我在第2段中所述。 – Artless 2013-04-28 18:59:08

    +0

    關於命名問題(I當我第一次看到你的答案時錯過了),我同意。但是,這**是一個客戶端問題。在這種情況下,maxReceivedMessageSize適用於客戶端。服務端的配額設置與客戶端的配額設置完全無關。通常情況下,雙方保持一致會更簡單,但僅僅是因爲服務可以接受。說一個1GB的文件並不意味着客戶端可以 - 除非它的配額足夠大。 – Tim 2013-04-28 19:07:37

    相關問題