我无法设置到我的控制器方法的路由。我总是在浏览器中收到以下错误:
<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>
我尝试创建一个简单的Web服务,以使用ASP.NET自托管功能将文本转换为语音。
在控制器代码下面:
using System.Web.Http;
namespace RESTService.Controller
{
public class TextToSpeechController : ApiController
{
[HttpGet, ActionName("Get")]
[AllowAnonymous]
public void Get()
{
}
}
}
应用程序:
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();
}
关于如何使它工作的建议将不胜感激。
我能够通过指定控制器所在的名称空间来使其工作:
var config = new HttpSelfHostConfiguration("http://localhost:8080");
config.Routes.MapHttpRoute("TTS", "{controller}/{text}",
new[] { "RESTService.Controller" });
答案 0 :(得分:-1)
我能够通过指定控制器所在的名称空间来使其工作:
var config = new HttpSelfHostConfiguration("http://localhost:8080");
config.Routes.MapHttpRoute("TTS", "{controller}/{text}",
new[] { "RESTService.Controller" });