我需要在Web服务'APIService'的'FtpConfiguration'控制器中调用名为'RetrieveFtpDetails'的函数, 。此Web服务也是作为现有项目的新项目创建的。找不到与请求URI'http:// localhost:7245/api/ftpconfiguration/retrieveftpdetails'相匹配的HTTP资源
RouteConfig.cs
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
WebApiConfig.cs
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}/{action}",
defaults: new { controller = "API" }
);
}
和FtpConfiguration控制器看起来像:
public class FtpConfigurationController : ApiController
{
[Route("api/ftpconfiguration/retrieveftpdetails")]
[HttpPost]
public List<string> RetrieveFtpDetails()
{
List<string> lstftpcongif;
using (APM context = new APM())
{
lstftpcongif = (from s in context.M_FtpConfigTable select
s.Mode).ToList();
}
return lstftpcongif;
}
}
,然后我叫http://localhost:7245/api/ftpconfiguration/retrieveftpdetails/然后得到如下结果:
<Error>
<Message>
No HTTP resource was found that matches the request URI 'http://localhost:7245/api/ftpconfiguration/retrieveftpdetails'.
</Message>
<MessageDetail>
No type was found that matches the controller named 'ftpconfiguration'.
</MessageDetail>
</Error>
为什么我得到这个错误?
为什么你'[HttpPost]'的方法是什么?你如何击中URL来测试它? –