WCF REST Web API 和 MVC 位于同一服务器和端口上
我正在考虑构建一个基于 REST 的系统,该系统仍然具有标准的浏览器样式访问权限。我的愿望是在同一台机器上安装这两个软件,但我有什么选择呢?
- 使用 IIS 托管网站和 REST 服务(不同的 URI,例如 http://mysite.com/和 http://mysite.com/api
- 使用 IIS 和一些我还不知道的魔法来拥有两个域映射到同一台机器但不同的服务(例如http://www.mysite.com 和 http://api.mysite.com
- 情况下可能使用路由表将请求定向到 MVC 或 WCF)。
将两种技术合并到一个服务中(在适当的 ,这将允许我拥有单个代码库和单个存储库访问。 codeplex 上的 WCF 页面 在其发行说明中提到,“未使用 MVC3 进行测试” - 这是否表明这是可能的 我不热衷于使用 MVC 进行 REST实现
,因为与我的网站的大部分交互都是通过 API 进行的,所以我希望将其作为重点。
I'm looking at putting together a REST based system which still has a standard browser style access. My desire is to have both of these on the same machine, but what are my options?
- Use IIS to host both the web-site and the REST service (different URIs, e.g. http://mysite.com/ and http://mysite.com/api
- Use IIS and some magic I don't yet know to have two domains mapped to the same machine but different services (e.g. http://www.mysite.com and http://api.mysite.com
- Combine the two technologies into a single service (that perhaps uses routing tables to direct the requests to MVC or WCF where appropriate).
My preference would be the third option, this would allow me to have a single code-base and single repository accessing. The WCF page on codeplex mentions in its release notes, "not tested with MVC3" - is this suggesting that this is a possible approach?
I'm not keen on using MVC for the REST implementation as it is intended that the majority of interaction with my site goes via API, so I want that as the focus.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经将联系人管理器移植为使用 MVC 3。尽管我们还没有进行详尽的测试,但它确实可以工作。关于 Web API 通常需要认识到的一件事是 MVC 路由和服务路由都是贪婪的。如果您的默认路由是第一个,那么 MVC 将尝试获取您的 HTTP 服务请求。您需要做的一件事是将您的服务路由放在 MVC 路由之前。如果遇到其他问题,您可能需要使用自定义路由约束。
I've ported the contact manager to use MVC 3. It definiately works though we've not done exhaustive testing. The one thing in general to cognizant of with regards to web api is that both MVC Routes and Service Route are greedy. If your default route is first then MVC will try to grab your HTTP Service requests. One thing you will want to do is put your Service Route first before your MVC routes. If you run into additional issues, you may need to use custom routing constraints.
在 http://webapicontrib.codeplex.com 中,有一个适用于 MVC 3 的示例。它位于示例中/实验文件夹。但是,它是使用 WCF Web API 的自定义版本构建的。但我不认为有必要这样。我一直想让示例的作者将其切换。
In http://webapicontrib.codeplex.com there is a sample that works with MVC 3. It is in the Samples/experimental folder. However, it was built with a custom version of WCF Web API. I don't believe it needs to be though. I've been meaning to get the author of the sample to switch it over.