简体   繁体   English

使用MVC的REST Web服务,这是一个好主意吗?

[英]REST Web Services using MVC, is it a good idea?

In .Net, I think about a web service as being a project type that you select from the menu, define your classes and methods then .Net does all this black magic under the hood to allow someone on the other side of the world to reference my web service and start coding using my classes and methods directly within their visual studio. 在.Net中,我认为Web服务是一种项目类型,您可以从菜单中选择,然后定义您的类和方法.Net会在引擎盖下完成所有这些黑魔法,以允许世界另一端的人参考我的网络服务,直接在他们的visual studio中使用我的类和方法开始编码。

So having this preconceived notion, when looking at writing REST web services using MVC 3 (I know MVC 4 has a REST api baked in but am waiting for a full release) I'm wondering all the usual stuff like "is this a good idea", "will this stand up to heavy use" and "am I just writing toy web services that other developers will laugh at". 所以有了这个先入为主的观念,当我看到使用MVC 3编写REST Web服务时(我知道MVC 4有一个REST api,但我正在等待完整版本)我想知道所有常见的东西,比如“这是一个好主意“,”这将经得起大量使用“和”我只是在写其他开发者会嘲笑的玩具网络服务“。

Now I think a lot of my anxiety is probably down to microsoft not having wrapped a big, overly complicated, bloated, shiny REST package around it yet. 现在我认为很多我的焦虑可能归结为微软尚未包装一个大的,过于复杂,臃肿,闪亮的REST包。 So I'm looking to have my anxiety relieved hopefully by people telling me yes MVC web services are perfectly good things to create. 因此,我希望人们告诉我,MVC网络服务是非常好的创造,我希望能让我的焦虑得到缓解。

Any help? 有帮助吗?

I've done it a few times, I am still using it in production and haven't got any complaints. 我已经完成了几次,我仍然在生产中使用它并且没有任何抱怨。 I actually think its a nice solution because it so simple to setup and maintain. 我实际上认为它是一个很好的解决方案,因为它设置和维护非常简单。 Not this incredibly xml-configuration-heavy wcf stuff.. 不是这个令人难以置信的xml配置重wcf东西..

You might want to also have a look at the WebAPI stuff that is in the process of being released (.net 4.5): 您可能还想查看正在发布的WebAPI内容(.net 4.5):

http://weblogs.asp.net/scottgu/archive/2012/02/23/asp-net-web-api-part-1.aspx http://weblogs.asp.net/scottgu/archive/2012/02/23/asp-net-web-api-part-1.aspx

It's very much to do with exposing plain html services. 这与暴露普通的html服务非常相关。

I would suggest you take a look at ServiceStack: http://www.servicestack.net/ . 我建议你看一下ServiceStack: http//www.servicestack.net/ It 's not only quite mature, but it can help you produce cleaner code. 它不仅非常成熟,而且可以帮助您生成更清晰的代码。

It really does depend on what you plan on doing with your application. 它确实取决于您计划对应用程序执行的操作。 Yes, you could write an MVC website that doubles as a RESTful service. 是的,您可以编写一个兼容RESTful服务的MVC网站。 However, you are then tying your UI layer very closely to your logic layer, and that is what you really need to consider. 但是,您将UI层紧密地绑定到逻辑层,这就是您真正需要考虑的问题。 I am working on an MVC site with a ServiceStack REST service (already mentioned by @Ioannis) . 我正在使用ServiceStack REST服务(已经由@Ioannis提到)的MVC站点上工作。 The reason that I did not make MVC my REST service is because I did not want any changes in my UI to potentially affect any third party application that might be using my logic service. 我没有将MVC作为我的REST服务的原因是因为我不希望我的UI中的任何更改可能会影响可能正在使用我的逻辑服务的任何第三方应用程序。 So, as long as you carefully consider the ramifications of making your site also your RESTful service, then either decision could be ok. 因此,只要您仔细考虑使您的网站也成为您的RESTful服务的后果,那么任何一个决定都可以。 :) :)

As others have mentioned here, ServiceStack provides a solid, terse REST Web Services Framework allowing you to effortlessly develop typed, idiomatic C# API's end-to-end. 正如其他人在此提到的那样, ServiceStack提供了一个可靠,简洁的REST Web服务框架,使您可以毫不费力地开发类型化,惯用的C#API端到端。

ServiceStack also includes a number of high-performance components that deeply integrates with ASP.NET MVC using the ServiceStack.Host.Mvc NuGet package. ServiceStack还包括许多高性能组件,这些组件使用ServiceStack.Host.Mvc NuGet包与ASP.NET MVC深度集成。

To learn more about the benefits ServiceStack can add to your MVC project see: http://www.servicestack.net/mvc-powerpack/ 要了解有关ServiceStack可以添加到MVC项目中的好处的更多信息,请参阅: http//www.servicestack.net/mvc-powerpack/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM