WCF - jak zwiększyć limit wielkości wiadomości

Mam usługę WCF, która zwraca 1000 rekordów z bazy danych do klienta. Mam ASP.NET klient WCF (dodałem referencję serwisową w asp.net Web application project to consumer WCF).

Podczas uruchamiania aplikacji klienckiej otrzymuję następujący komunikat:

Maksymalny rozmiar wiadomości dla wiadomości przychodzących (65536) został przekroczone. Aby zwiększyć kwotę, użyj nieruchomość MaxReceivedMessageSize na odpowiedni element wiążący.

Any pomóc? Jak zwiększyć limit wielkości wiadomości?

Author: marc_s, 2009-05-19

13 answers

Będziesz chciał czegoś takiego, aby zwiększyć kontyngenty wielkości wiadomości, w aplikacji .config lub Web.plik config:

<bindings>
    <basicHttpBinding>
        <binding name="basicHttp" allowCookies="true"
                 maxReceivedMessageSize="20000000" 
                 maxBufferSize="20000000"
                 maxBufferPoolSize="20000000">
            <readerQuotas maxDepth="32" 
                 maxArrayLength="200000000"
                 maxStringContentLength="200000000"/>
        </binding>
    </basicHttpBinding>
</bindings>

I użyj wiążącej nazwy w konfiguracji punktu końcowego, np.

...
bindingConfiguration="basicHttp"
...

Uzasadnienie wartości jest proste, są one wystarczająco duże, aby pomieścić większość wiadomości. Możesz dostosować ten numer do swoich potrzeb. Niska wartość domyślna jest w zasadzie tam, aby zapobiec atakom typu DOS. Uczynienie go 20000000 pozwoliłoby na dystrybucję Atak DOS aby był skuteczny, domyślny rozmiar 64k wymagałby bardzo dużej liczby klientów, aby obezwładnić większość serwerów w dzisiejszych czasach.

 551
Author: Nate,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-12-09 09:30:07

Jeśli nadal otrzymujesz ten Komunikat o błędzie podczas korzystania z klienta testowego WCF, dzieje się tak dlatego, że Klient ma osobne ustawienie MaxBufferSize.

Aby poprawić problem:

  1. Kliknij prawym przyciskiem myszy na Plik konfiguracyjny węzeł u dołu drzewa
  2. wybierz Edytuj za pomocą SvcConfigEditor

zostanie wyświetlona lista edytowalnych ustawień, w tym MaxBufferSize.

Uwaga: automatycznie generowane klienty proxy również Ustaw domyślnie MaxBufferSize na 65536.

 137
Author: Michael Rodrigues,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-05-21 19:44:40

Jeśli tworzysz swoje wiązania WCF dynamicznie, oto kod do użycia:

BasicHttpBinding httpBinding = new BasicHttpBinding();
httpBinding.MaxReceivedMessageSize = Int32.MaxValue;
httpBinding.MaxBufferSize = Int32.MaxValue;
// Commented next statement since it is not required
// httpBinding.MaxBufferPoolSize = Int32.MaxValue;
 85
Author: Bharath K,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-12-29 14:32:43

Klient testowy WCFposiada własną konfigurację klienta.

Uruchom klienta testowego i przewiń do dołu. Jeśli dwukrotnie klikniesz węzeł pliku konfiguracyjnego, zobaczysz reprezentację XML. Jak widać maxReceivedMessageSize jest 65536.

Aby to edytować, kliknij prawym przyciskiem myszy węzeł drzewa plików konfiguracyjnych i wybierz Edytuj za pomocą SvcConfigEditor. Po otwarciu edytora rozwiń powiązania i kliknij dwukrotnie powiązanie, które zostało wygenerowane automatycznie.

Możesz tutaj edytować wszystkie właściwości, w tym maxReceivedMessageSize. Po zakończeniu kliknij File - Save.

Na koniec, po powrocie do okna klienta testowego WCF, kliknij Tools-Options.

Uwaga: odznacz konfigurację zawsze regeneruj podczas uruchamiania usług .

 39
Author: Jodee Dex Page,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-02-17 11:40:39

I found the easy way

- - - kliknij prawym przyciskiem myszy webconfig lub plik konfiguracyjny aplikacji i kliknij Edytuj konfigurację WCF i przejdź do bingdigs ans wybierz usługę i prawo side show maxReciveMessageSize podaj dużą liczbę - - -

 16
Author: NC64,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-03-30 06:39:22

Rozwiązuję problem ... w następujący sposób

    <bindings>
  <netTcpBinding>
    <binding name="ECMSBindingConfig" closeTimeout="00:10:00" openTimeout="00:10:00"
      sendTimeout="00:10:00" maxBufferPoolSize="2147483647" maxBufferSize="2147483647"
      maxReceivedMessageSize="2147483647" portSharingEnabled="true">
      <readerQuotas maxArrayLength="2147483647" maxNameTableCharCount="2147483647"
          maxStringContentLength="2147483647" maxDepth="2147483647"
          maxBytesPerRead="2147483647" />
      <security mode="None" />
    </binding>
  </netTcpBinding>
</bindings>
<behaviors>
  <serviceBehaviors>
    <behavior name="ECMSServiceBehavior">
      <dataContractSerializer ignoreExtensionDataObject="true" maxItemsInObjectGraph="2147483647" />
      <serviceDebug includeExceptionDetailInFaults="true" />
      <serviceTimeouts transactionTimeout="00:10:00" />
      <serviceThrottling maxConcurrentCalls="200" maxConcurrentSessions="100"
        maxConcurrentInstances="100" />
    </behavior>
  </serviceBehaviors>
</behaviors>
 7
Author: Rajesh Kuamr Chekuri,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-03-22 05:36:14

<bindings>
  <wsHttpBinding>
    <binding name="wsHttpBinding_Username" maxReceivedMessageSize="20000000"          maxBufferPoolSize="20000000">
      <security mode="TransportWithMessageCredential">
        <message clientCredentialType="UserName" establishSecurityContext="false"/>
      </security>
    </binding>
  </wsHttpBinding>
</bindings>

<client>
  <endpoint
            binding="wsHttpBinding"
            bindingConfiguration="wsHttpBinding_Username"
            contract="Exchange.Exweb.ExchangeServices.ExchangeServicesGenericProxy.ExchangeServicesType"
            name="ServicesFacadeEndpoint" />
</client>

 6
Author: Hemant Soni,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-01-26 12:38:19

Rozwiązałem mój problem na Bing Maps WPF w moim projekcie za pomocą CalculateRoute (). Rozwiązaniem w moim przypadku było ustawienie maxReceivedMessageSize i maxReceivedMessageSize na atrybut "httpTransport" dla sekcji "customBinding".

Ustawiłem w aplikacjach.plik konfiguracyjny (es. myApp.config) Ta konfiguracja:

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_IGeocodeService" />
            <binding name="BasicHttpBinding_IRouteService" />
        </basicHttpBinding>
        <customBinding>
            <binding name="CustomBinding_IGeocodeService">
                <binaryMessageEncoding />
              <httpTransport manualAddressing="false" maxBufferPoolSize="524288"
                                maxReceivedMessageSize="2147483647" allowCookies="false" authenticationScheme="Anonymous"
                                bypassProxyOnLocal="false" decompressionEnabled="true" hostNameComparisonMode="StrongWildcard"
                                keepAliveEnabled="true" maxBufferSize="2147483647" proxyAuthenticationScheme="Anonymous"
                                realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
                                useDefaultWebProxy="true" />
            </binding>
            <binding name="CustomBinding_IRouteService">
                <binaryMessageEncoding />
              <httpTransport manualAddressing="false" maxBufferPoolSize="524288"
                                maxReceivedMessageSize="2147483647" allowCookies="false" authenticationScheme="Anonymous"
                                bypassProxyOnLocal="false" decompressionEnabled="true" hostNameComparisonMode="StrongWildcard"
                                keepAliveEnabled="true" maxBufferSize="2147483647" proxyAuthenticationScheme="Anonymous"
                                realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
                                useDefaultWebProxy="true" />
            </binding>
        </customBinding>
    </bindings>
    <client>
        <endpoint address="http://dev.virtualearth.net/webservices/v1/geocodeservice/GeocodeService.svc"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IGeocodeService"
            contract="BingServices.IGeocodeService" name="BasicHttpBinding_IGeocodeService" />
        <endpoint address="http://dev.virtualearth.net/webservices/v1/geocodeservice/GeocodeService.svc/binaryHttp"
            binding="customBinding" bindingConfiguration="CustomBinding_IGeocodeService"
            contract="BingServices.IGeocodeService" name="CustomBinding_IGeocodeService" />
        <endpoint address="http://dev.virtualearth.net/webservices/v1/routeservice/routeservice.svc"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IRouteService"
            contract="BingServices.IRouteService" name="BasicHttpBinding_IRouteService" />
        <endpoint address="http://dev.virtualearth.net/webservices/v1/routeservice/routeservice.svc/binaryHttp"
            binding="customBinding" bindingConfiguration="CustomBinding_IRouteService"
            contract="BingServices.IRouteService" name="CustomBinding_IRouteService" />
    </client>
</system.serviceModel>
 6
Author: Francesco Germinara,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-05-11 00:07:27

Kolejna ważna rzecz do rozważenia z mojego doświadczenia..

Radzę nie maksymalizować maxBufferPoolSize, ponieważ bufory z puli nigdy nie są uwalniane, dopóki domena aplikacji (tj. Pula aplikacji) nie przetworzy się.

Okres dużego ruchu może spowodować użycie dużej ilości pamięci i nigdy nie wypuszczenie jej.

Więcej Szczegółów tutaj:

 3
Author: Valerio Gentile,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-23 12:26:20

Nie zapomnij, że aplikacja.będzie brana pod uwagę konfiguracja punktu wejścia wykonania, a nie tego w projekcie biblioteki klas zarządzającym wywołaniami usługi sieciowej, jeśli takie istnieje.

Na przykład, Jeśli pojawi się błąd podczas uruchamiania testu jednostkowego, musisz skonfigurować odpowiednią konfigurację w projekcie testowym.

 2
Author: Gab,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-07-26 07:54:36

Dostałem ten błąd podczas korzystania z tych ustawień w Internecie.config

System.ServiceModel.ServiceActivationException

Ustawiam takie ustawienia:

      <service name="idst.Controllers.wcf.Service_Talks">
    <endpoint address="" behaviorConfiguration="idst.Controllers.wcf.Service_TalksAspNetAjaxBehavior"
      binding="webHttpBinding" contract="idst.Controllers.wcf.Service_Talks" />
  </service>
  <service name="idst.Controllers.wcf.Service_Project">
    <endpoint address="" behaviorConfiguration="idst.Controllers.wcf.Service_ProjectAspNetAjaxBehavior"
      binding="basicHttpBinding" bindingConfiguration="" bindingName="largBasicHttp"
      contract="idst.Controllers.wcf.Service_Project" />
  </service>
</services>

<bindings>
<basicHttpBinding>
    <binding name="largBasicHttp" allowCookies="true"
             maxReceivedMessageSize="20000000"
             maxBufferSize="20000000"
             maxBufferPoolSize="20000000">
        <readerQuotas maxDepth="32"
             maxArrayLength="200000000"
             maxStringContentLength="200000000"/>
    </binding>
</basicHttpBinding>

 1
Author: FARHAD AFSAR,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-01-22 09:53:41

Dla HTTP:

<bindings>
  <basicHttpBinding>
    <binding name="basicHttp" allowCookies="true"
             maxReceivedMessageSize="20000000" 
             maxBufferSize="20000000"
             maxBufferPoolSize="20000000">
        <readerQuotas maxDepth="200" 
             maxArrayLength="200000000"
             maxBytesPerRead="4096"
             maxStringContentLength="200000000"
             maxNameTableCharCount="16384"/>
    </binding>
  </basicHttpBinding>
</bindings>

Dla TCP:

<bindings>
  <netTcpBinding>
    <binding name="tcpBinding"
             maxReceivedMessageSize="20000000"
             maxBufferSize="20000000"
             maxBufferPoolSize="20000000">
      <readerQuotas maxDepth="200"
           maxArrayLength="200000000"
           maxStringContentLength="200000000"
           maxBytesPerRead="4096"
           maxNameTableCharCount="16384"/>
    </binding>
  </netTcpBinding>
</bindings>

Ważne:

Jeśli próbujesz przekazać złożony obiekt, który ma wiele połączonych obiektów (np. drzewo struktury danych, lista, która ma wiele obiektów...), komunikacja nie powiedzie się bez względu na to, jak zwiększysz kwoty. W takich przypadkach należy zwiększyć liczbę obiektów zawierających:

<behaviors>
  <serviceBehaviors>
    <behavior name="NewBehavior">
      ...
      <dataContractSerializer maxItemsInObjectGraph="2147483646"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
 1
Author: Jacob,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-07-25 10:27:06

Dla mnie wystarczyło dodać maxReceivedMessageSize="2147483647" do aplikacji klienckiej.config. Serwer pozostał nietknięty.

 0
Author: ashilon,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-07-24 14:50:15