简体   繁体   English

使用Asp.net mvc或Web服务会更好吗?

[英]Would it be better to use Asp.net mvc or web services?

I have asp.net mvc app written a couple of years ago and the more I add to it, I tend to make REST/AJAX calls to the controller to get data from it. 我有几年前编写的asp.net mvc应用程序,我添加的越多,我倾向于对控制器进行REST / AJAX调用以从中获取数据。

My question is do I carry on working in this way or should I expose the data as a separate REST services (WCF way of doing things)? 我的问题是,我是否继续以这种方式工作,还是应该将数据作为单独的REST服务(WCF处理方式)公开?

It feels that the boundary on what a mvc app is designed to do and the design of web service is getting blurred. 感觉mvc应用程序设计的界限和Web服务的设计越来越模糊。 The Mvc app (apart from separation) initially produced web pages, now it is being used to provide service based data. Mvc应用程序(除了分离)最初生成网页,现在它用于提供基于服务的数据。

JD JD

I see two possible scenarios 我看到两种可能的情况

Single web app. 单个网络应用。 In this case you carry on adding methods to the controller. 在这种情况下,您继续向控制器添加方法。 This is good because it keeps relevant to the controller functionality in one place and will save you time. 这很好,因为它在一个地方与控制器功能保持相关,可以节省您的时间。 It is not suitable if the controller is being called from another web application. 如果从另一个Web应用程序调用控制器,则不适用。 Simple, ugly but works, takes little time for development and much time for maintenance. 简单,丑陋但有效,开发时间短,维护时间长。

Web app + web service. 网络应用+网络服务。 You can segregate data retrieval methods into the service interface. 您可以将数据检索方法分离到服务接口中。 The positive side is that you system becomes much more modular and independent, which is good for maintenance. 积极的一面是,您的系统变得更加模块化和独立,这有利于维护。 If you predict that there will be other methods that will be added soon or if the methods are used by other web applications, then this path is probably better than extending the current web app. 如果您预测将会很快添加其他方法,或者其他Web应用程序使用这些方法,则此路径可能比扩展当前Web应用程序更好。 The negative side is that the new service will require some refactoring to the current web application and will take time to be developed/tested etc. This decision brings more complexity, but makes your application easy to be extended. 消极的一面是新服务需要对当前的Web应用程序进行一些重构,并且需要时间来开发/测试等。这个决定带来了更多的复杂性,但使您的应用程序易于扩展。

I think WCF has several advantages over MVC if you are strictly sending data, specifically in terms of data formats being unambiguous (SOAP vs. using home-brewed encodings), industry-wide tool support, excellent support for different types of bindings (ie not just HTTP), various transport level services, nice logging and tracing capabilities, etc. 我认为如果你严格发送数据,WCF比MVC有几个优点,特别是在数据格式明确(SOAP与使用自制的编码),行业范围的工具支持,对不同类型的绑定的优秀支持(即不是只是HTTP),各种传输级服务,良好的日志记录和跟踪功能等。

In the end though, it boils down to: is there a significant enough advantage to going with WCF for your case . 最后,它归结为: 对于你的情况 ,使用WCF是否有足够的优势。 That is something that you'd have to figure out yourself. 这是你必须弄清楚的事情。

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

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