I have ASP.NET web application. The template creates default web api controller ValuesController. I am trying to create console application to self-host using Microsoft.AspNet.WebApi.OwinSelfHost version 5.2.6. Solution structure looks like:
Startup.cs in SelfHost.Server, agree! not a good name, is looks like:
HttpConfiguration config = new HttpConfiguration();
config.Routes.MapHttpRoute(
"DefaultApi",
"api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional });
app.UseWebApi(config);
And this is how I am using it:
static void Main(string[] args)
{
var uri = "http://localhost:44382/";
using (WebApp.Start<Startup>(uri))
{
Console.WriteLine($"Server started at {uri} on {DateTime.Now}");
HttpClient client = new HttpClient();
var response = client.GetAsync(uri + "api/values").Result;
Console.WriteLine(response.Content.ReadAsStringAsync().Result);
Console.ReadKey();
}
}
Running console application gives this error:
{"Message":"No HTTP resource was found that matches the request URI 'http://localhost:44382/api/values'.","MessageDetail":"No type was found that matches the controller named 'values'."}
Using postman I get "Could not get any response"
Question Please, how can I do this?