9

Does MVC have to be RESTful?

Is there a way to make a SOAP service using MVC pattern?

Would the input request actually go into the View first and then into the Controller then the Model eg:

Request -> View -> Controller -> Model

but in doing so, that's no longer MVC pattern. (that's right isn't it?)

How else would we get a typed response using SOAP but still adhere to (or be close to) the MVC pattern. Would MVVM be more suitable pattern to this situation at all instead?

Seph
  • 7,864
  • 10
  • 58
  • 86
  • 1
    I don't understand why MVC gets so much attention. – duffymo Feb 14 '12 at 10:55
  • @duffymo I agree... it is not my choice – Seph Feb 14 '12 at 13:32
  • @duffymo and Seph > what technologies are you using? – Adi Jan 23 '13 at 07:55
  • I have no problem with MVC. It has nothing to with services, REST or SOAP, because they have no view. You're applying a buzzword/pattern where it has no business. – duffymo Jan 23 '13 at 10:23
  • @duffymo the problem is my boss considers different return formats (xml/json) as 'Views'... more so he's convinced that we could just add 'html views' to our 'MVC API' and then we will have a fully working website - instead of designing the website to use the API as an API or having a custom back end or anything of that sort... now we have an API that returns html pages that make other API calls that return html pages as well. It's a mess :) – Seph Mar 02 '14 at 13:06
  • There has to be a server side component that really is part of the view. It mediates between the client and the back end services, but it's really part of the view. Isolate all that page generation stuff inside that and let the back end services be completely independent. – duffymo Mar 02 '14 at 15:13

3 Answers3

27

REST describes how you interface with the application, while MVC is how you implement the application. An application implemented using MVC can be RESTful or not.

SOAP is a protocol for interfacing with the application, which can be implemented using MVC.

In MVC the request goes into the controller, which creates a model for the view.

Request -> [Controller] -> Model -> [View] -> Response
Guffa
  • 640,220
  • 96
  • 678
  • 956
  • for typed SOAP to work (eg: WSDL), you would still need to wrap the request in a type safe wrapper, no? – Seph Feb 14 '12 at 13:31
1

HTTP was designed to be RESTful. Detailed discussion about what is REST was here. MVC has no restriction about to be RESTful or not. ASP.Net MVC supports REST style of web development. You can make you web site RESTful or not, it's your choice. SOAP is protocol. In .Net is better to use WCF to deal with SOAP. WCF services can be deployed together with your ASP.Net MVC application. But we do not have MVC implementation inside WCF. In general we don't have UI part in Web / WCF services at all.

Community
  • 1
  • 1
paramosh
  • 2,248
  • 1
  • 13
  • 23
0

The request is routed to an action on your controller, which uses a model (which you define; it's merely a structure that represents the data that your action and view will operate on). This action returns an ActionResult, which often is, but does not have to be, a ViewResult (which essentially just executes the view page you specified, using the model you specified, if any). However, you don't have to return a View; You can create any sort of ActionResult you want. You can return XML, JSON, SOAP, binary content, whatever.

MVC is restful in nature, but it is not strictly adherent to REST and can be tailored to whatever you see fit. You could have your controller speak SOAP, but my question is why would you, if that work is already done for you in other technologies (such as WCF)?

moribvndvs
  • 40,946
  • 9
  • 129
  • 143