MVC和放大器;同一个解决方案中的Web API项目 [英] MVC & Web Api projects within same Solution

查看:119
本文介绍了MVC和放大器;同一个解决方案中的Web API项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MVC 4项目顶上坐着一个N层应用程序。我现在必须要能够programattically消耗应用程序的要求。我创建了沿着一侧的MVC项目坐镇,再次N层之上的应用程序相同的解决方案中的一个新的Web API项目。

I have an MVC 4 project sitting atop an N-tier application. I now have a requirement to to be able to consume the application programattically. I have created a new Web Api project within the same solution which sits along side the MVC project, again atop the N-tier application.

不过,我不清楚,如何这一切工作的MVC层是启动项目:它建立我的DI,automapper等,是我的项目部署到服务器。

But I am unclear as to how this all works as the MVC layer is the startup project: it sets up my DI, automapper etc and is the project I deploy to the server.

那么我们应该如何这一切都被设置?我可以设置我的MVC项目路由所有/ API请求到新的Web API项目?还是在Web API项目需要进行单独部署?

So how should this all be set up? Can I set up my MVC project to route all /api requests to the new Web Api project? Or does the Web Api project need to be deployed seperately?

我不希望做任何非常规的,所以如果有设置此功能,pleae点我在正确的方向的一个更常见的方式。

I dont want to be doing anything unconventional so if there is a much more common way of setting this up, pleae point me in the right direction.

感谢。

推荐答案

的WebAPI是微软面向应用就像WCF的替代服务。但是WCF使用SOAP协议的WebAPI使用HTTP协议进行通信。

WebApi is an alternative Service oriented application from Microsoft just like WCF. But WCF uses SOAP protocol and WebAPI uses HTTP protocol for communication.

所以,如果你正在使用WCF为您的MVC应用程序提供服务,你会单独承载WCF服务和消费由MVC应用程序的服务,你必须单独托管您的WebAPI项目和Web应用程序提供服务(完全相同的方式MVC)。

So if you are using WCF to provide service for your MVC application you would host that wcf service seperately and consume its service by MVC application, EXACTLY same way you have to host your WebAPI project seperately and provide service to your Web application (MVC).

由于某种原因,如果你想让他们(MVC和的WebAPI)在同一个项目中使用,按照这个规则,从这篇文章。

for some reasons if you want them (MVC and WebAPI) to use in the same project, follow this rules from this article.

<一个href=\"http://odeto$c$c.com/blogs/scott/archive/2013/07/01/on-the-coexistence-of-asp-net-mvc-and-webapi.aspx\">http://odeto$c$c.com/blogs/scott/archive/2013/07/01/on-the-coexistence-of-asp-net-mvc-and-webapi.aspx

希望有所帮助。

这篇关于MVC和放大器;同一个解决方案中的Web API项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆