我的团队想从WCF升级到Web API。我们有一个有效的asp.net Web表单应用程序,已从VS2010导入到VS2012。到现在为止还挺好。
但是现在当我尝试创建一个单独的Web API项目时,我看到没有可用的Web API模板。我可以找到的最接近的东西是通过创建MVC 4应用程序并将项目模板设置为WebAPI 。我按照这种方式进行,一切都变得很完美。我有一个带有示例 Controller 的有效API,可以通过从浏览器进行调用来调用该 Controller 。
唯一的缺点是,这种特殊方法带来了自己的负担。我创建的MVC 4项目包含JQUERY和其他库,以及一些我可能不需要的其他文件夹。我想要的只是Web API结构-而不是多余的负担。
我尝试使用在线搜索找到模板,但是发现的程序包无法正常工作,并且评级很差。
我希望我已经正确地说明了我的问题。我现在希望得到一些反馈:)谢谢。
最佳答案
在Visual Studio 2013中
使用。
结果
从我所看到的,Visual Studio执行以下操作:
注释
随后,我建议遵循相同的步骤,首先右键单击Controllers文件夹而不是项目。这会将新 Controller 放置在Controllers文件夹中,而不是放在根级别。
执行以下步骤后,从Visual Studio中获取自述文件:
Visual Studio has added the full set of dependencies for ASP.NET Web API 2 to project 'RowersCode.Web'.
The Global.asax.cs file in the project may require additional changes to enable ASP.NET Web API.
Add the following namespace references:
- using System.Web.Http;
- using System.Web.Routing;
If the code does not already define an Application_Start method, add the following method:
protected void Application_Start()
{
}
Add the following lines to the beginning of the Application_Start method:
GlobalConfiguration.Configure(WebApiConfig2.Register);
关于asp.net - 将Web API添加到现有的asp.net Web窗体应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20538119/