I try to setup a HttpSelfHostServer in C#. I use this class to start the server:
class Route
{
HttpSelfHostServer server;
public int Port { get { return 8080; } }
public void Routestart()
{
string baseUrl = "http://localhost:" + this.Port + "/";
HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(baseUrl);
config.Routes.MapHttpRoute(
name: "test1",
routeTemplate: "api/AutomaticTest/{Action}/{test}",
defaults: new
{
controller = "AutomaticTest",
test = RouteParameter.Optional
});
server = new HttpSelfHostServer(config);
server.OpenAsync();
}
public void Routestop()
{
server.CloseAsync();
}
}
Moreover, I have a Controller-class which looks like:
class AutomaticTestController : ApiController
{
[HttpGet]
[ActionName("status")]
public string Status()
{
return "example";
}
}
When I open http://localhost:8080/api/AutomaticTest/status in a web browser, I get the following result:
<Error>
<Message>No HTTP resource was found that matches the request URI
'http://localhost:8080/api/AutomaticTest/status'.</Message>
<MessageDetail>No type was found that matches the controller named
'AutomaticTest'.</MessageDetail></Error>
Obviously, I made something wrong, but I don't know what. Does anybody have a hint? I wonder how the HttpSelfHostServer instance finds the AutomaticTestControllerClass. I assume that I have create some link to the class? If so, how do I do that?
Thanks a lot for all constructive answers.