title: ApiController returning 504 - The server did not return a complete response for this request. Server returned 0 bytes
body: <p>I have a call to my ApiController which is returning a 504 and I just cannot work out what I am doing wrong...</p>
  <p>Can anyone see my problem?</p>
  <p>This is the controller:</p>
  <pre><code>public class SA_GetAllLocationsController : ApiController
  {
      [Route(&quot;SA_GetAllLocations&quot;)]
      [HttpGet]
      public List&lt;SA_Locations&gt; Get()
      {
          List&lt;SA_Locations&gt; result = SADatastore.Functions.Location.GetAllLocations(Settings.Default.ConnectionString);
  
          return result;
      }
  }
  </code></pre>
  <p>This is the class SA_Locations which was generated by Entity Framework Database First...</p>
  <pre><code>public partial class SA_Locations
  {
      public SA_Locations()
      {
          this.SA_Items = new HashSet&lt;SA_Items&gt;();
      }
  
      public string LocationID { get; set; }
      public string BuildingID { get; set; }
      public string Name { get; set; }
      public string Description { get; set; }
      public string MISID { get; set; }
      public string GPSCoords { get; set; }
      public string QRCode { get; set; }
      public Nullable&lt;bool&gt; Signable { get; set; }
      public Nullable&lt;bool&gt; Auditable { get; set; }
      public Nullable&lt;bool&gt; Bookable { get; set; }
      public Nullable&lt;bool&gt; Entrance { get; set; }
      public Nullable&lt;bool&gt; Exit { get; set; }
      public Nullable&lt;bool&gt; Active { get; set; }
      public System.DateTime LastUpdated { get; set; }
  
      public virtual SA_Buildings SA_Buildings { get; set; }
      public virtual ICollection&lt;SA_Items&gt; SA_Items { get; set; }
  }
  </code></pre>
  <p>I have written a small &quot;status&quot; function that works perfectly and looks like this:</p>
  <pre><code>public HttpResponseMessage Get()
      {
          return new HttpResponseMessage()
          {
              Content = new StringContent(
                  &quot;SA service is running and ready to accept connections!&quot;,
                  Encoding.UTF8,
                  &quot;text/html&quot;
              )
          };
      }
  </code></pre>
  <p>I just cannot work out why the SA_Locations appears to be being returned with no errors when I debug but the response I see in Fiddler is:</p>
  <blockquote>
  <p>504 - The server did not return a complete response for this request. Server returned 0 bytes</p>
  </blockquote>
  <p>Is the object too complex to be returned?</p>
  <p>Any help would be very much appreciated!</p>
  <p>Trev</p>
  <p><strong>UPDATE</strong></p>
  <p>I decided to try and see what happens if I just return pure JSON from the controller so I re-wrote the controller as follows:</p>
  <pre><code>public class SA_GetAllLocationsController : ApiController
  {
      [Route(&quot;SA_GetAllLocations&quot;)]
      [HttpGet]
      public HttpResponseMessage Get()
      {
          List&lt;SA_Locations&gt; result = SADatastore.Functions.Location.GetAllLocations(Settings.Default.ConnectionString);
  
          string output = JsonConvert.SerializeObject(result);
  
          return new HttpResponseMessage()
          {
              Content = new StringContent(
                  output,
                  Encoding.UTF8,
                  &quot;application/json&quot;
              )
          };
      }
  }
  </code></pre>
  <p>It now actually throws an error serializing the SA_Locations object to a string!</p>
  <p>The error message is:</p>
  <blockquote>
  <p>An exception of type 'Newtonsoft.Json.JsonSerializationException' occurred in Newtonsoft.Json.dll but was not handled in user code</p>
  <p>Additional information: Error getting value from 'SA_Buildings' on 'System.Data.Entity.DynamicProxies.SA_Locations_720FF8784B152496318F87BCB674E344B97C0446B16D4DC2BDDC381D88C048B9'.</p>
  </blockquote>
  <p>So, it does point toward something to do with SA_Locations, which as I said, is a class generated by Entity Framework Database first....</p>
  <p>Getting closer but no idea why that object won't serialize?</p>