在自托管 webapi 控制台应用程序项目中,我无法SayHello
使用http://localhost:9998/api/shri/flows/config
.
错误:
{
"Message": "No HTTP resource was found that matches the request URI 'http://localhost:9998/api/shri/flows/config'.",
"MessageDetail": "No route data was found for this request."
}
控制器:
class ConfigController : ApiController
{
[HttpGet, Route("{id}/flows/config")]
public string SayHello([FromUri] string id)
{
return "Hello " + id;
}
}
启动:
public class Startup
{
// This code configures Web API. The Startup class is specified as a type
// parameter in the WebApp.Start method.
public void Configuration(IAppBuilder appBuilder)
{
// Configure Web API for self-host.
HttpConfiguration config = new HttpConfiguration();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
appBuilder.UseWebApi(config);
}
}
为了保持自托管 webapi 运行,我有以下内容:
public class Program
{
static void Main()
{
Uri myUri = new Uri(@"http://localhost:9998/");
// Let have our configurations readY
HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(myUri);
// configure routes
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
HttpSelfHostServer server = new HttpSelfHostServer(config);
// Start listening
server.OpenAsync().Wait();
Console.WriteLine("WebApi hosted on " + myUri.AbsoluteUri + " It can be tested now");
Console.ReadLine();
}
}
我错过了什么?