El TecnoBaúl de Kiquenet

Kiquenet boring stories

WCF Quotas and IIS Limits

Posted by kiquenet en 14 abril 2015

Exceptions about Quotas and limits using WCF for uploading files or another method:

System.ServiceModel.EndpointNotFoundException: There was no endpoint listening at http://localhost:8080/oms/FileService.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details. —> System.Net.WebException: The remote server returned an error: (404) Not Found.

System.InsufficientMemoryException: Failed to allocate a managed memory buffer of 279620368 bytes. The amount of available memory may be low. —> System.OutOfMemoryException: Exception of type ‘System.OutOfMemoryException’ was thrown.

The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.

Review “quotas” of Bindings
http://stackoverflow.com/questions/1573606/wcf-maxreceivedmessagesize-maximum-message-size-quota-exceeded

I can view System.ServiceModel.Diagnostics.MessageNotLoggedQuotaExceeded in the svclog file.

No se registró el mensaje porque el tamaño supera la cuota configurada
Message not logged because its size exceeds configured quota

Request Limits <requestLimits>
maxAllowedContentLength
Specifies the maximum length of content in a request, in bytes.
maxAllowedContentLength has type uint, its maximum value is 4,294,967,295 bytes = 3,99 gb

<security>
    <requestFiltering>
        <requestLimits maxAllowedContentLength="209715200" />
    </requestFiltering>
</security>

209715200 are 200 MB

 

In addition to maxAllowedContentLength, the maxRequestLength on the server side in your WCF confgiration needs to be increased as well.

<system.web>
  <!–Increase ‘maxRequestLength’ to needed value: 100mb (value is in kilobytes)–>
  <httpRuntime maxRequestLength="102400"/>

the default web site doesn’t override it using:

"%WINDIR%\System32\inetsrv\appcmd.exe" list config "Default web site" -section:requestFiltering

Note about SubStatusCode:

WebExceptionStatus – ProtocolError = 7
HTTP Substatus
404.13 Content Length Too Large
404.14 URL Too Long
404.15 Query String Too Long
404.10 Request Header Too Long

WebException hasn’t SubStatusCode, only HttpException
https://msdn.microsoft.com/en-us/library/system.web.httpresponse.substatuscode(v=vs.110).aspx           

Useful Troubleshooting Failed Requests – Tracing in IIS
http://www.iis.net/learn/troubleshoot/using-failed-request-tracing/troubleshooting-failed-requests-using-tracing-in-iis

using (ServerManager serverManager = new ServerManager())
{
   Configuration config = serverManager.GetWebConfiguration("Default Web Site");
   ConfigurationSection requestFilteringSection = config.GetSection("system.webServer/security/requestFiltering");
   ConfigurationElement requestLimitsElement = requestFilteringSection.GetChildElement("requestLimits");
   ConfigurationElementCollection headerLimitsCollection = requestLimitsElement.GetCollection("headerLimits");

   ConfigurationElement addElement = headerLimitsCollection.CreateElement("add");
   addElement["header"] = @"Content-type";
   addElement["sizeLimit"] = 100;
   headerLimitsCollection.Add(addElement);

   serverManager.CommitChanges();
}

EndpointNotFoundException with InnerExcception (WebException) hasn’t SubStatusCode, only HttpException:

catch (System.ServiceModel.EndpointNotFoundException ex)
           {
               var iex = ex.InnerException;
               TestContext.WriteLine(iex.ToString());
               if (iex is System.Net.WebException)
               {
                   var msg = "no http status code available";
                   var wex = (iex as System.Net.WebException);
                   if (wex.Status == System.Net.WebExceptionStatus.ProtocolError)
                   {
                       var response = wex.Response as System.Net.HttpWebResponse;
                       if (response != null)
                       {
                           msg = "HTTP Status Code: " + (int)response.StatusCode;
                       }
                   }
                   TestContext.WriteLine(msg);
               }

Bit Calculator
http://www.matisse.net/bitcalc/?input_amount=200&input_units=megabytes&notation=legacy

References:

http://stackoverflow.com/questions/4022434/how-to-set-the-maxallowedcontentlength-to-500mb-while-running-on-iis7

http://www.iis.net/configreference/system.webserver/security/requestfiltering/requestlimits
https://msdn.microsoft.com/en-us/library/ms689462(VS.90).aspx
http://www.iis.net/learn/troubleshoot/using-failed-request-tracing/troubleshooting-failed-requests-using-tracing-in-iis

http://stackoverflow.com/questions/8113211/difficulty-using-wcf-for-uploading-large-files

http://plainoldstan.blogspot.com.es/2011/02/wcfmaxsizeofmessagetolog-and-not-logged.html
http://stackoverflow.com/questions/1573606/wcf-maxreceivedmessagesize-maximum-message-size-quota-exceeded

https://dotnetforyou.wordpress.com/2011/02/02/the-maximum-message-size-quota-for-incoming-messages-65536-has-been-exceeded-to-increase-the-quota-use-the-maxreceivedmessagesize-property-on-the-appropriate-binding-element/

http://stackoverflow.com/questions/6690451/wcf-exists-and-partially-working-but-for-some-calls-returns-no-endpoint-listeni?rq=1

Anuncios

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s

 
A %d blogueros les gusta esto: