tamaño superó supera para necesario máxima mensaje maxbuffersize matriz los longitud leer lector error datos cuota crear contenido cadena búfer almacenar c# wcf configuration-files

c# - superó - Error de WCF: se ha excedido la cuota máxima de tamaño de mensaje para los mensajes entrantes(65536)



se superó la cuota de longitud máxima de la matriz 16384 (1)

Mi configuración:

  • Cliente ASP.NET alojado en IIS Express
  • Servicio WCF alojado en la aplicación de consola
  • Ejecutando Visual Studio.NET 2012 en modo Admin

Estoy tratando de devolver 2 objetos List desde un servicio WCF. Mi configuración funciona bien cuando devuelvo solo 1 lista de objetos. Pero cuando devuelvo 2 objetos List obtengo el error:

Se ha excedido la cuota máxima de tamaño de mensaje para los mensajes entrantes (65536). Para aumentar la cuota, use la propiedad MaxReceivedMessageSize en el elemento de enlace apropiado.

Sé que esta pregunta se ha hecho muchas veces en este sitio y en otros sitios también. He intentado casi todo lo publicado en Internet con varias combinaciones del ARCHIVO CONFIG pero todavía no funcionó para mí.

Configuración del cliente:

<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>

Configuración del servidor:

<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>


Eso sería porque no especificó en el servidor qué enlace usar. Echemos un vistazo a la configuración de su servidor:

En <bindings> está creando una configuración de enlace para <basicHttpBinding> , y lo está nombrando name="basicHttpBinding" . Además, su nombre de punto final es <endpoint name="basicHttpBinding" ...> y su enlace es binding="basicHttpBinding" . Sin embargo , no se refiere a su configuración de enlace , sino al tipo de enlace. Por lo tanto, en realidad está usando la configuración predeterminada para basicHttpBinding .

Para solucionar esto, primero nombre su endpoint y configuración de enlace de manera diferente. Por ejemplo, <endpoint name="basicEndpoint" ... > y <binding name="myBasicBinding" ... > . Luego debe asignar su configuración de enlace a su punto final con este atributo: bindingConfiguration="myBasicBinding" .

Aquí está la configuración del cliente:

<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>

Aquí está la configuración del servidor:

<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>

No se olvide de update service reference en su cliente para obtener la configuración correcta.