简体   繁体   English

用于XML / JSON REST API的MVC2或WCF?

[英]MVC2 or WCF for an XML/JSON REST API?

I spent a long time learning how to customise WCF from the point of view of adding authentication etc over a RESTful service; 我花了很长时间从RESTful服务添加身份验证等角度学习如何自定义WCF; I built some custom service hosts, then added the ability to use an IOC container to actually create the service instance etc etc. 我构建了一些自定义服务主机,然后添加了使用IOC容器来实际创建服务实例等的功能。

We have iPhone/iPad apps plus some other gadgety-type things (technical term!) that now use these (XML on the i-platform, JSON for browser-based) and I am very pleased with the performance and the ease with which we can add new operations etc. 我们有iPhone / iPad应用程序以及其他一些小工具类型(技术术语!)现在使用这些(i-platform上的XML,基于浏览器的JSON),我对我们的性能和易用性非常满意可以添加新的操作等

I learnt all the foibles of the DataContract serializers (and now use them in isolated cases to read/write objects outside of WCF) and after that steep learning curve, but now that we have them I'm very happy with them all. 我学习了DataContract序列化程序的所有缺陷(现在在隔离的情况下使用它们来读取/写入WCF之外的对象)并在那个陡峭的学习曲线之后,但是现在我们拥有它们,我对它们都非常满意。

Now we have a series of new Web projects for which I jumped at the chance of using MVC - and have been suitably impressed with that; 现在我们有了一系列新的Web项目,我抓住了使用MVC的机会 - 并对此印象深刻; the model binding, in particular, really kicks arse. 模特绑定,特别是真正踢屁股。

I'm now looking at similar RESTful apis for these web projects (they will all be similar sites but different branding and minor changes in business logic depending on custom need). 我现在正在为这些Web项目寻找类似的RESTful api(它们都是类似的站点,但不同的品牌和业务逻辑的微小变化取决于自定义需求)。 Originally, I expected that all this work on WCF would stand us in good stead - but MVC has its own development path for RESTful XML/JSON and I'm now caught between the two. 最初,我预计WCF上的所有这些工作都会让我们处于有利地位 - 但MVC有自己的RESTful XML / JSON开发路径,现在我已经陷入了两者之间。

If you're writing an MVC site would you ever use WCF to implement its REST API? 如果您正在编写MVC站点,您是否会使用WCF来实现其REST API?

I'll throw out one argument for using WCF - that, properly written, it can be isolated to run as a windows service without the need for a Web Server. 我将抛弃一个使用WCF的参数 - 正确编写后,它可以被隔离以作为Windows服务运行而无需Web服务器。 However, that seems like a desperate case! 然而,这似乎是一个绝望的情况!

Update 更新

I should say that I've now implemented 3 separate large REST services using MVC 2 & 3, and it's a joy to work with. 我应该说我现在已经使用MVC 2和3实现了3个独立的大型REST服务,并且很高兴能够使用它。 I've written model binders to wrap around WCF's DataContractSerializer for XML and of course JSON support is just fine. 我已经编写了模型绑定器来包装WCF的DataContractSerializer for XML,当然JSON支持就好了。 I won't go back now. 我现在不会回去。

I've never used WCF, but I am currently using MVC2 to implement a REST API. 我从未使用过WCF,但我目前正在使用MVC2来实现REST API。

For the most part it's well suited, but there are some gaps, and it's involved a bit of a learning curve. 在大多数情况下,它非常适合,但存在一些差距,并且它涉及一些学习曲线。 I've needed to use MVCContrib for better XML support. 我需要使用MVCContrib来获得更好的XML支持。 I've used MVC futures to support sending a JSON object to an action method (see: http://haacked.com/archive/2010/04/15/sending-json-to-an-asp-net-mvc-action-method-argument.aspx ). 我使用MVC期货来支持将JSON对象发送到action方法(请参阅: http//haacked.com/archive/2010/04/15/sending-json-to-an-asp-net-mvc-action -method-argument.aspx )。 I also needed to take the source for this and alter it so it could support XML. 我还需要为此获取源代码并对其进行更改以便它可以支持XML。

I've heard there are some REST frameworks that sit on top of .NET MVC, but I've not had a chance to try them out. 我听说有一些REST框架位于.NET MVC之上,但我没有机会尝试它们。

If you're familiar with WCF and it worked well last time, then I would be tempted to stick with what you know. 如果你对WCF很熟悉并且上次运作良好,那么我很想坚持你所知道的。

I've used WCF to do REST for quite a while and my recommendation would be to use MVC. 我已经使用WCF做了很长一段时间的REST,我的建议是使用MVC。 If you only want to deal with XML and Json and if your URI space is relatively simple then you could probably could get by with WCF. 如果您只想处理XML和Json,并且如果您的URI空间相对简单,那么您可能可以使用WCF。 However, once you step out of the basic stuff then you need to be very familiar with WCF to work around its default behaviour. 但是,一旦你走出基本的东西,那么你需要非常熟悉WCF来解决它的默认行为。

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

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