2013-01-03 7 views
18

Powiel możliwe:
The maximum message size quota for incoming messages (65536) has been exceededjak zwiększyć MaxReceivedMessageSize podczas wywoływania WCF od C#

Używam WCF do wysyłania i pobierania plików. Zamieszczanie jest udany, ale kiedy pobierania dużego pliku znalazłem ten błąd

Błąd: Maksymalna kwota rozmiar wiadomości dla wiadomości przychodzących (65536) została przekroczona. Aby zwiększyć limit, użyj właściwości MaxReceivedMessageSize o wartości na odpowiednim elemencie wiązania.

Mój plik Service.config ma następujący kod.

<system.web> 
    <compilation debug="true" /> 
    <httpRuntime executionTimeout="4800" maxRequestLength="2147483647" /> 


    </system.web> 
    <system.serviceModel> 
    <bindings> 
     <basicHttpBinding> 
     <binding maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferPoolSize="524288"> 
      <readerQuotas maxDepth="32" maxStringContentLength="2147483647" 
      maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> 
     </binding> 
     </basicHttpBinding> 
     <!--<webHttpBinding> 
     <binding maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" /> 
     </webHttpBinding>--> 
    </bindings> 
    <services> 
     <service name="WITSService.WITSService"> 
     <clear /> 
     <endpoint binding="basicHttpBinding" contract="WITSService.WITSService" /> 
     </service> 
    </services> 

    <behaviors> 
     <serviceBehaviors> 
     <behavior> 
      <serviceMetadata httpGetEnabled="true"/> 
      <serviceDebug includeExceptionDetailInFaults="false"/> 
      <dataContractSerializer maxItemsInObjectGraph="2147483646"/> 
     </behavior> 
     </serviceBehaviors> 
     <endpointBehaviors> 
     <behavior name="myEndPointBehavior"> 
      <dataContractSerializer maxItemsInObjectGraph="2147483646"/> 
     </behavior> 
     </endpointBehaviors> 
    </behaviors> 

    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 

może ktoś mi pomóc w jaki sposób zwiększyć MaxReceivedMessageSize

Odpowiedz

30

Zmień ustawienie customBinding w pliku web.config, aby użyć większych wartości domyślnych. Wybrałem 2MB, ponieważ jest to rozsądny rozmiar. Oczywiście ustawienie go na 2 GB (zgodnie z sugestią kodu) będzie działało, ale będzie bardziej podatne na ataki. Wybierz rozmiar większy niż Twoje największe żądanie, ale nie jest zbyt duży.

Sprawdź to: Using Large Message Requests in Silverlight with WCF

<system.serviceModel> 
    <behaviors> 
    <serviceBehaviors> 
     <behavior name="TestLargeWCF.Web.MyServiceBehavior"> 
     <serviceMetadata httpGetEnabled="true"/> 
     <serviceDebug includeExceptionDetailInFaults="false"/> 
     </behavior> 
    </serviceBehaviors> 
    </behaviors> 
    <bindings> 
    <customBinding> 
     <binding name="customBinding0"> 
     <binaryMessageEncoding /> 
     <!-- Start change --> 
     <httpTransport maxReceivedMessageSize="2097152" 
         maxBufferSize="2097152" 
         maxBufferPoolSize="2097152"/> 
     <!-- Stop change --> 
     </binding> 
    </customBinding> 
    </bindings> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/> 
    <services> 
    <service behaviorConfiguration="Web.MyServiceBehavior" name="TestLargeWCF.Web.MyService"> 
     <endpoint address="" 
       binding="customBinding" 
       bindingConfiguration="customBinding0" 
       contract="TestLargeWCF.Web.MyService"/> 
     <endpoint address="mex" 
       binding="mexHttpBinding" 
       contract="IMetadataExchange"/> 
    </service> 
    </services> 
</system.serviceModel> 
Powiązane problemy