here is my situation. I have 1 solution containing 2 projects: Web API and Web Form. I set both projects as Startup projects. In the code behind, I call the Web API like this:

private HttpResponseMessage DownloadFile(int id)
    using (var client = new HttpClient())
        client.BaseAddress = new Uri("http://localhost:8096/");
        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/pdf"));
        HttpResponseMessage response = client.GetAsync("api/document/" + id).Result;
        return response;

When I click Start in Visual Studio, if the Web API is running on different port from WebForm, it will "actively refused the connection" (as the exception said).

So my question is: how can I make Web API accept the call without changing its port? I don't want both projects to run on the same port. Why can't I call it normally as I usually do with many external APIs?

Thanks for your help.

Related posts

Recent Viewed