web-dev-qa-db-fra.com

Le serveur distant a renvoyé une réponse inattendue: (413) Request Entity Too Large.

J'essaye de construire un service d'application WCF, en utilisant FW4.0. Mon service fonctionne correctement lors du transfert de l'objet EntiryFramework entre le serveur et le client. Mais je rencontre des problèmes pour transmettre un objet EF du client au serveur.

Voici plus de détails sur mon environnement: - Le service s'exécute en mode débogage localement sur IIS - J'exécute tout cela sur mon Windows 7 - J'utilise Visual Studio 2010 sur FW4. 0

J'essaie d'envoyer un objet (tblClient) au serveur pour enregistrer l'enregistrement, mais continue d'avoir l'erreur (413) Request Entity Too Large. Voici la pile complète:

System.ServiceModel.ProtocolException occurred
      HResult=-2146233087
      Message=The remote server returned an unexpected response: (413) Request Entity Too Large.
      Source=mscorlib
      StackTrace:
        Server stack trace:
           at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory`1 factory, WebException responseException, ChannelBinding channelBinding)
           at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
           at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
           at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
           at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
           at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
           at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(iMessage message)
        Exception rethrown at [0]:
           at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(iMessage reqMsg, iMessage retMsg)
           at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
           at ClientApp.ServiceReference1.IService.SaveClient(tblClient client)
           at ClientApp.ServiceReference1.ServiceClient.SaveClient(tblClient client) in C:\dufh\WPF Project\ClientApp\Service References\ServiceReference1\Reference.vb:line 2383
           at ClientApp.ViewModel.ClientViewModel.SaveClient() in C:\dufh\WPF Project\ClientApp\ViewModel\ClientViewModel.vb:line 48
      InnerException: System.Net.WebException
           HResult=-2146233079
           Message=The remote server returned an error: (413) Request Entity Too Large.
           Source=System
           StackTrace:
                at System.Net.HttpWebRequest.GetResponse()
                at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
           InnerException:

J'ai fait quelques recherches et tous pointent vers le maxBufferSize et/ou maxBufferPoolSize et/ou maxReceivedMessageSize qui n'est pas assez grand dans la configuration client App.Config. Je les ai donc mis à la valeur maximale: maxBufferSize = "2147483647" maxBufferPoolSize = "2147483647" maxReceivedMessageSize = "2147483647" Mais l'erreur persiste.

Voici mon application client complète.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.diagnostics>
    <sources>
      <!-- This section defines the logging configuration for My.Application.Log -->
      <source name="DefaultSource" switchName="DefaultSwitch">
        <listeners>
          <add name="FileLog"/>
          <!-- Uncomment the below section to write to the Application Event Log -->
          <!--<add name="EventLog"/>-->
        </listeners>
      </source>
    </sources>
    <switches>
      <add name="DefaultSwitch" value="Information" />
    </switches>
    <sharedListeners>
      <add name="FileLog"
           type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
           initializeData="FileLogWriter"/>
      <!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
      <add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="MVVM Sampling"/>
    </sharedListeners>
  </system.diagnostics>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IService" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"/>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:7803/Service1.svc" binding="basicHttpBinding"
          bindingConfiguration="BasicHttpBinding_IService" contract="ServiceReference1.IService"
          name="BasicHttpBinding_IService" />
    </client>
  </system.serviceModel>
</configuration>

et le service Web.Config WCF complet Web.Config

<?xml version="1.0"?>
<configuration>

  <system.web>
    <compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>

    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IService" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">
          <readerQuotas maxDepth="200" maxStringContentLength="8388608" maxArrayLength="16384" maxBytesPerRead="2147483647" maxNameTableCharCount="16384" />
        </binding>
      </basicHttpBinding>
    </bindings>

    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- 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="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />


  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
  <connectionStrings>
    <add name="MaitreEntities" connectionString="metadata=res://*/Schemat.csdl|res://*/Schemat.ssdl|res://*/Schemat.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=INFOFILE2\SQL2008R2;initial catalog=0001ConneryFerland;user id=sa;password=Kermit80;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>


Any help would be very welcome :-)
33
Hugo

Pour mémoire

Je crois que j'ai compris. Le Web.Config du service n'a pas les informations de liaison. J'y ai mis cette info, et le tour est joué!

<bindings>
      <basicHttpBinding>
        <binding maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text">
          <readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
        </binding>
      </basicHttpBinding>
</bindings>

Notez ici que la liaison n'avait pas de nom spécifié.

70
Hugo

Vous n'avez pas de point de terminaison explicite (c'est-à-dire défini dans votre fichier de configuration) pour votre service, de sorte que la configuration de liaison que vous avez déclarée ("BasicHttpBinding_IService") n'est pas utilisée. WCF fournit un point de terminaison par défaut avec une liaison par défaut (basicHttpBinding sauf si vous l'avez remplacé dans la section protocolMapping du fichier de configuration).

Vous avez deux façons de résoudre ce problème dans le fichier de configuration de votre service:

Vous pouvez définir la configuration "BasicHttpBinding_IService" par défaut en supprimant l'attribut name:

<binding maxBufferPoolSize="2147483647".....

Ou vous définissez explicitement un noeud final dans la configuration et affectez votre configuration de liaison à l'attribut bindingConfiguration du noeud final.

<services>
    <endpoint address="" 
              binding="basicHttpBinding"
              bindingConfiguration="BasicHttpBinding_IService"     
              contract="ServiceReference1.IService"  />
</services>
13
Tim

Une autre façon de résoudre ce problème et de mieux consulter le fichier web.config consiste à modifier le fichier web.config avec l '"Éditeur de configuration de service Microsoft" (C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\SvcConfigEditor.exe)

0
Hugo

Si vous créez une liaison personnalisée, par exemple MybasicBinding,

  <basicHttpBinding>
      <binding name="MybasicBinding" closeTimeout="01:00:00" openTimeout="01:00:00" receiveTimeout="01:00:00" sendTimeout="01:00:00"
               maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" >
            <readerQuotas maxDepth="32" maxBytesPerRead="200000000" 
             maxArrayLength="200000000" maxStringContentLength="200000000" />
      </binding>
  </basicHttpBinding>

Pour éviter l'erreur 413, n'oubliez pas de spécifier bindingConfiguration = "MybasicBinding" pour point de terminaison de service as,

<endpoint address="" binding="basicHttpBinding" bindingConfiguration="MybasicBinding" contract="WCFService.IService" />
0
Aki

si aucune liaison n'est spécifiée et que httpsgetenabled est vrai, vous devrez peut-être définir basichttpsbinding dans le web.config de votre application de service

<bindings>
  <basicHttpsBinding>
    <binding maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text">
      <readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
    </binding>
  </basicHttpsBinding>
0
Hasmukh Jain