我正在尝试从Pluralsight APS.NET Webapi简介中运行该示例。它是一个带有程序类
的控制台应用程序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();
}
}
}
和控制器
using System.Web.Http;
namespace ASPNETWebAPISelfHost
{
public class SimpleController : ApiController
{
public IEnumerable<string> Get()
{
return new string[] { "Hello", "ControllerAPI" };
}
}
}
当我在VS中运行它时,HttpClient能够检索json数据,但是当我从Fiddler进行调用时,我得到502 Server主动拒绝连接。我按照视频中的说明以管理员身份运行VS. 我怎样才能解决这个错误