title: Calling WebApi from Windows Service
body: <p>I am trying to call the following method from the OnStart() method of the windows service, but the windows service starts and stops and throws an error.</p>
  
  <pre><code> static async Task RunAsync()
      {
              LightSpeedContext&lt;RightHireUnitOfWork&gt; _context;
              var client = new HttpClient();
  
              _context = new LightSpeedContext&lt;RightHireUnitOfWork&gt;("default");
  
              client.BaseAddress = new Uri("https://api.xyz.com/");
              client.DefaultRequestHeaders.Accept.Clear();
              client.DefaultRequestHeaders.TryAddWithoutValidation(
                  "X-SmartToken",
                  "1dfaaad541c45031c8b92bfab3ssssssssssb5644c368f3");
  
              var content = new StringContent("", Encoding.UTF8,
                                  "application/json");
              string config = "v1/assessments?status=NEW";
              HttpResponseMessage response = null;
  
              try
              {
                  response = await client.GetAsync(config);
              }
              catch (HttpRequestException httpEx)
              {
                  // determine error here by inspecting httpEx.Message         
              }
  
              if (response.IsSuccessStatusCode)
              {
                  ListResult lr = await response.Content.ReadAsAsync&lt;ListResult&gt;();
  
                  List&lt;SmartRecruiters.AssessmentOrder&gt; lAsmtOrders = lr.content;
  </code></pre>
  
  <p>// Do other processing here                   </p>
  
  <pre><code>            }
  
      }
  </code></pre>
  
  <p>The OnStart method is as follows:</p>
  
  <pre><code>    protected override void OnStart(string[] args)
      {
          this.WriteToFile("Simple Service started {0}");
  
          // Need to call the RunAsync method here...
  
      }
  </code></pre>
  
  <p>I tried making OnStart async, but it didn't help.  Any thoughts on how I can successfully make the call? </p>