I'm unable to setup a route to my controller method. I always get the following error in the browser:
<Error>
<Message>
No HTTP resource was found that matches the request URI 'http://localhost:8080/TextToSpeech'.
</Message>
<MessageDetail>
No type was found that matches the controller named 'TextToSpeech'.
</MessageDetail>
</Error>
I try to create a simple web service to convert text to speech using ASP.NET self hosting.
Below the controller code:
using System.Web.Http;
namespace RESTService.Controller
{
public class TextToSpeechController : ApiController
{
[HttpGet, ActionName("Get")]
[AllowAnonymous]
public void Get()
{
}
}
}
And the application:
var config = new HttpSelfHostConfiguration("http://localhost:8080");
config.Routes.MapHttpRoute("TTS", "{controller}", new { action = "Get" });
using (HttpSelfHostServer server = new HttpSelfHostServer(config))
{
server.OpenAsync().Wait();
Console.WriteLine("Press Enter to quit.");
Console.ReadLine();
}
Advice on how I can get this to work would be much appreciated.
I was able to get it to work by specifying the namespace where the controller resides:
var config = new HttpSelfHostConfiguration("http://localhost:8080");
config.Routes.MapHttpRoute("TTS", "{controller}/{text}",
new[] { "RESTService.Controller" });
I was able to get it to work by specifying the namespace where the controller resides:
var config = new HttpSelfHostConfiguration("http://localhost:8080");
config.Routes.MapHttpRoute("TTS", "{controller}/{text}",
new[] { "RESTService.Controller" });
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.