测试中遇到如下问题:
<Error>
<Message>
No HTTP resource was found that matches the request URI 'http://localhost:37331/api/action/FindByModule?moduleId=1'.
</Message>
<MessageDetail>
No type was found that matches the controller named 'action'.
</MessageDetail>
</Error>
解决办法:
controler类的名字要和 访问的action名字一致,也就是说标红的名字要一致。
http://localhost:37331/api/action/FindByModule?moduleId=1
public class ActionController : ApiController
{
[HttpGet]
// [ActionName("FindByModule")]
public string FindByModule(Int64 moduleId)
{
return "ddddd";
}
}
class WebApiService
{
public WebApiService()
{
var config = new HttpSelfHostConfiguration("http://localhost:37331");
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional });
var server = new HttpSelfHostServer(config);
server.OpenAsync().Wait();
Console.WriteLine("Web Api Server is opened");
}
}