title: WebAPI: using async methods in business logic
body: <p>The aim is to make controller that uses async method in my custom service.</p>
  
  <p>Controller:</p>
  
  <pre><code>[Route("api/data/summary")]
  [HttpGet]
  public async Task&lt;IHttpActionResult&gt; Get()
  {
      var result = await DataService.GetDataObjects();
      return Ok(result);
  }
  </code></pre>
  
  <p>Service:</p>
  
  <pre><code>public static async Task&lt;IEnumerable&lt;DataObject&gt;&gt; GetDataObjects()
  {
      var apiKey = "some-api-key";
      var path = "path-to-external-service";
      using (var client = new HttpClient())
      {
          var dataToProcess = // some data object
  
          client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
          client.BaseAddress = new Uri(path);
  
          HttpResponseMessage response = await client.PostAsJsonAsync("", dataToProcess);
          var content = await response.Content.ReadAsStringAsync();
  
          var result = MakeEntities(content); // some logic
  
          return result;
      }
  }
  </code></pre>
  
  <p>But I came across with the problem that controller's action returns empty result before service actually finished processing data.</p>
  
  <p>Could you please advice how to implement it correctly?</p>