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?
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.
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.
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, aViewResult
(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)?