8

如果我想使用 WebAPI 作为服务来连接到不同服务器上的多个数据库并检索我的 MVC 应用程序将使用的数据,那么最好的方法是什么?

我不希望 ApiController(s) 与我的 MVC 项目在同一个项目中,所以我需要添加一个新的 WebApi 项目(删除所有除了控制器和模板添加的东西以拥有一个干净的项目),我的 MVC 应用程序会参考吗?

这是我用来学习 WebAPI 的教程/博客文章列表:

ASP.NET Web API - 带有可下载示例代码的截屏系列 http://weblogs.asp.net/jgalloway/archive/2012/03/16/asp-net-web-api-screencast-series-with-downloadable-sample-代码部分 1.aspx

使用 HttpClient 使用 ASP.NET Web API 服务

http://debugmode.net/2012/03/03/creating-first-http-service-using-asp-net-web-api-part1-of-many/ http://debugmode.net/2012/03/ 07/消费-asp-net-web-api-service-using-httpclient-part2-of-many/

使用 ASP.NET Web API 和 MVC4 的 CRUD 操作

http://www.dotnetglobe.com/2012/03/crud-operation-using-aspnet-web-api-in.html http://www.dotnetglobe.com/2012/03/crud-operation-using-aspnet -web-api-in_28.html

为 ASP.Net Web API oData 服务创建一个 .Net 可查询客户端 http://blog.petegoo.com/index.php/2012/03/11/creating-a-net-queryable-client-for-asp-net- web-api-odata-服务/

使用 HttpClient 使用 ASP.NET Web API REST 服务 http://www.johnnycode.com/blog/2012/02/23/sumption-your-own-asp-net-web-api-rest-service/

ASP.NET Web API 的客户端支持 https://msmvps.com/blogs/theproblemsolver/archive/2012/03/13/client-side-support-with-the-asp-net-web-api.aspx

创建和使用 ASP.Net Web API REST 服务 - MVC4 http://www.askamoeba.com/Opensource/Opensourcedetail/144/Create-and-Consume-ASP-Net-Web-API-REST-Services-MVC4

使用 MediaTypeFormatter 和 OData 支持通过 ASP.NET Web API 构建和使用 REST 服务

http://robbincremers.me/2012/02/16/building-and-sumption-rest-services-with-asp-net-web-api-and-odata-support/

将 JSON.NET 与 ASP.NET Web API 结合使用

http://blogs.msdn.com/b/henrikn/archive/2012/02/18/using-json-net-with-asp-net-web-api.aspx

在 ASP.NET Web API 中为逗号分隔值 (CSV) 格式创建自定义 CSVMediaTypeFormatter

http://www.tugberkugurlu.com/archive/creating-custom-csvmediatypeformatter-in-asp-net-web-api-for-comma-separated-values-csv-format

在 ASP.NET Web API 中实现 CORS 支持

http://blogs.msdn.com/b/carlosfigueira/archive/2012/02/20/implementing-cors-support-in-asp-net-web-apis.aspx

我如何看待 Web API

http://thedatafarm.com/blog/asp-net/how-i-see-web-api/

4

1 回答 1

7

您可以使用完全不同的项目来托管您的 Web API 控制器。然而在这种情况下,您需要考虑部署。

Web API 只是一个 Web 项目。它将有自己的配置文件。它很可能会在自己的工作进程中运行(取决于您如何部署它)。

因此,如果您将 Web API 划分出来,您将获得更大的灵活性,但最终可能会复制大量配置。

我的建议是,如果您这样做,请确保两个项目都与相同的基础服务项目通信。如果此 Web API 可能被第三方使用,那么分区也是有意义的。

于 2012-04-13T11:55:21.843 回答