0

I am trying to run the sample from the Pluralsight Introduction to the APS.NET Webapi. It is a console application with a program class

using System.Web.Http.SelfHost;
using System.Web.Http;
using System.Net.Http;
namespace ASPNETWebAPISelfHost
{
    class Program
    {
        static void Main(string[] args)
        {
            var config =
              new HttpSelfHostConfiguration("http://localhost:8999");
            config.Routes.MapHttpRoute("DefaultRoute",
            "{controller}/{id}",
            new { id = RouteParameter.Optional });
        //custom message processing
        //var server = new HttpSelfHostServer(config,
        //      new MyNewSimpleMessageHandler());
        //controller message processing
        var server = new HttpSelfHostServer(config);
        server.OpenAsync();
        Console.ReadLine();
        var client = new HttpClient(server);
        client.GetAsync(
          "http://localhost:8999/simple").ContinueWith((t) =>
          {
              var result = t.Result;
              result.Content.ReadAsStringAsync().ContinueWith((rt) =>
              {
                  Console.WriteLine("Client got " + rt.Result);
              });
          });
        Console.WriteLine("Opening Web API SelfHost");
        Console.ReadLine();
    }
}

}

and a controller

using System.Web.Http;

namespace ASPNETWebAPISelfHost
{
  public class SimpleController : ApiController
  {
    public IEnumerable<string> Get()
    {
      return new string[] { "Hello", "ControllerAPI" };

    }
  }
}

When I run it in VS, the HttpClient is able to retrieve the json data, but when I make the call from Fiddler, I get a 502 Server actively refuses connection. I am running VS as an administrator as instructed in the video. How can I get around this error

pthalacker
  • 2,056
  • 3
  • 20
  • 37

0 Answers0