Request Entity Too Large Exception in Web API

The UploadReadAheadSize property establishes the number of bytes a Web server will read into a buffer and pass to an ISAPI extension. This occurs once per client request. The ISAPI extension receives any additional data directly from the client. The range is from 0 to &HFFFFFFFF (4 GB).

For more details on this property please check the URL – https://msdn.microsoft.com/en-us/library/ms525310%28v=vs.90%29.aspx

 

To navigate to this setting, use the following steps:

  • Launch “Internet Information Services (IIS) Manager”
  • Expand the Server field
  • Expand Sites
  • Select the site your application is in.
  • In the Features section, double click “Configuration Editor”
  • Under “Section” select: system.webServer>serverRuntime

 

For my case, customer had maximum file size less than 50 MB, so we set it to 52428800 i.e. 50 MB.

Please note that the value is in Bytes.

 

This resolved the issue for us and file uploads and downloads worked fine.

 

I hope this helps!

 

SOURCE: https://blogs.msdn.microsoft.com/dsnotes/2015/08/21/large-file-upload-failure-for-web-application-calling-wcf-service-413-request-entity-too-large/

 

 

 

Advertisements

Web API and C# out Values

 

public IHttpActionResult GetResponse(int id)
{
    int outputInt;
    string outputString;

    YourMethodWithOutParameters(id, out outputInt, out outputString);

    return Ok(new
    {
        Id = id,
        OutputInt = outputInt,
        OutputString = outputString,
    });
}

 

Source: https://stackoverflow.com/questions/39944732/web-api-and-c-sharp-out-values

 

debug web service project in same solution as web site project

In your solution file, click properties go to the Startup project node (if it is not already selected)

Next select Multiple startup projects. Select your website and your webservice and in the Action column make sure both of them have “Start” selected.

Now when you debug your website and put a break point in you webservice it should hit the break point.

Thats all i can think of for your problem. Hope it helps.

https://forums.asp.net/t/1428325.aspx?debug%20web%20service%20project%20in%20same%20solution%20as%20web%20site%20project%20

 

 

Web API error: The ‘ObjectContent`1’ type failed to serialize the response body for content type ‘application/xml

Add following liners in dbcontext constructor

public DbContext() // dbcontext constructor
            : base("name=ConnectionStringNameFromWebConfig")
{
     this.Configuration.LazyLoadingEnabled = false;
     this.Configuration.ProxyCreationEnabled = false;
}

Another change has to do for App_Start / WebApiConfig.cs class in my MVC Web API project

var json = config.Formatters.JsonFormatter;
json.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects;
config.Formatters.Remove(config.Formatters.XmlFormatter);