locked
Difference between REST WCF and ASP.NET MVC from Architecture point of view RRS feed

  • Question

  • Hi,

    We have an application developed using WCF service at backend and Silverlight as client. Now we want to migrate the application to ASP.NET MVC.

    Rather than going for MVC, if we expose the existing WCF service methods in a RESTful way (adding WebGet/WebInvoke attribute to service methods) and consume the same in aspx/html frontend, will it make any differences with ASP.NET MVC ? As per my understanding goes, ASP.NET MVC framework has done the same thing.  There the controller methods are being consumed in a restful way into the View. If there are no differences from security,performance and scalability point of view, we can reuse the WCF services in RESTful way and save our huge effort to develop "Controller" method from scratch.

    Please suggest.

    Regards

    ronit_rc

    Sunday, May 13, 2012 1:31 PM

Answers

  • ronit_rc wrote:


    1) I am having a System in place,developed in Silverlight, which uses WCF services in backend. Now, I want to migrate the project using some other web technology, in Microsoft Web stack (ASP.NET,ASP.NET MVC etc.). I n this sceanario, which solution is best? If I expose the WCF services in REST way and consume the the same ASPX/HTML client, I can reuse the services, which saves a huge dev. effort. Please suggest.

    The fastest solution is to change the endpoint for RIA to json (now it's supported) and consume data via jquery.
    This new library has been renamed to upshot and you can read about it here:
    http://www.asp.net/single-page-application
    http://www.asp.net/single-page-application/an-introduction-to-spa/overview/landingpage

    As a longer term, I would migrate all the solution using webapi. Depending on your code it could be straightforward or a difficult task.
     > 2) Say, I want to develop  a System, where data entry parts will be handled

    using Windows Form and Reporting/Approval part will be handled in Web. The application will be distributed. In this scanario, should we use WCF or Web API? I beleive in order to consume Web API in Windows Form, we need to POST the request to URI. Is it a good option? Please suggest.

    Sounds like a CRUD with a machine state, a solution that can be easily afforded with both SOA and REST.
    The main difference in terms of application lifecycle is versioning.
    The REST solution is more flexible (but on the other side the clients should be ready to handle 404 endpoints as the server side evolves).
    The SOA solution is more 'rpc' and suitable when, in addition to the pure CRUD, you have some other stuff to do.

    Developing CRUD with Webapi is really easy and a matter of few minutes.
    From Windows Forms you have HttpClient class and DataContractSerializer (or DataJsonContractSerializer). In a few lines you can CRUD your data using all the REST classical verbs (GET/PUT/POST/DELETE/PATCH)


    Raffaele Rialdi  http://www.iamraf.net
    Weblog: http://blogs.ugidotnet.org/raffaele
    Microsoft MVP profile https://mvp.support.microsoft.com/profile/raffaele
    UGIdotNET - http://www.ugidotnet.org/


    Raffaele Rialdi [MVP] My articles and videos: http://www.iamraf.net Italian blog: http://blogs.ugidotnet.org/raffaele
    • Marked as answer by ronit_rc Monday, May 14, 2012 9:40 AM
    Monday, May 14, 2012 7:34 AM

All replies

  • ronit_rc wrote:


    Hi,

    We have an application developed using WCF service at backend and Silverlight as client. Now we want to migrate the application to ASP.NET MVC.

    Rather than going for MVC, if we expose the existing WCF service methods in a RESTful way (adding WebGet/WebInvoke attribute to service methods) and consume the same in aspx/html frontend, will it make any differences with ASP.NET MVC ? As per my understanding goes, ASP.NET MVC framework has done the same thing.  There the controller methods are being consumed in a restful way into the View. If there are no differences from security,performance and scalability point of view, we can reuse the WCF services in RESTful way and save our huge effort to develop "Controller" method from scratch.

    Please suggest.

    Exposing a service with webget/webinvoke does not imply automatically being restful.
    Rest is an architectural style embracing Http as an application plarform.
    As Richardson suggest there is a flavour of adherence ('maturity level') to the rest architecture that is directly tied to the level of control you have over Http.

    Said that, MVC give you a quite good control, but even better is WebAPI that is now part of the MVC4 framework.
    With WebAPI you have full control over all the aspects of Http (requests, responses, headers, ...) adding interesting features such as MediaTypeFormatters and other goodies.

    The top of the maturity level in REST is reached by using "hypermedia as the engine of application platform". This means that the response should contain the application state in addition to the requested raw data.
    WebAPI let you control this kind of responses very easily and I strongly suggest this framework for building real restful services.

    HTH


    Raffaele Rialdi  http://www.iamraf.net
    Weblog: http://blogs.ugidotnet.org/raffaele
    Microsoft MVP profile https://mvp.support.microsoft.com/profile/raffaele
    UGIdotNET - http://www.ugidotnet.org/


    Raffaele Rialdi [MVP] My articles and videos: http://www.iamraf.net Italian blog: http://blogs.ugidotnet.org/raffaele
    Sunday, May 13, 2012 2:24 PM
  • Hi,

    Thanks for the answer. It seems from your answer that  the architecture behind the  following two approach is different:

    1) Consuming a REST WCF service which returns JSON response, in ASPX/HTML front end, using JQuery.

    2) Consuming the Controller methods which returns JSONRESULT, in ASPX/HTML front end using JQuery.

    which approach is faster performance and scalability wise?

    Regards

    ronit_rc

     

    Sunday, May 13, 2012 4:38 PM
  • ronit_rc wrote:


    Hi,

    Thanks for the answer. It seems from your answer that  the architecture behind the  following two approach is different:

    1) Consuming a REST WCF service which returns JSON response, in ASPX/HTML front end, using JQuery.

    2) Consuming the Controller methods which returns JSONRESULT, in ASPX/HTML front end using JQuery.

    which approach is faster performance and scalability wise?

    You're welcome.

    Webapi is neither of the two.
    Webapi use a 'special' apicontroller that let you manage the response over the specific webapi pipeline. This provide a number of advantages and the performance is absolutely excellent.

    Furthermore, most of the performance/scalability problems are normally due to the serializer, not the technology used for Rest. My personal experience tell me that:
    - the choice of the technology is mostly a matter of architecture and rapidity in terms of lifecycle (coding, test, etc.)
    - the serializer is a matter of context. The default serializer is good for certain scenarios but very poor in others. For this reason, starting from RC, Webapi will ship json.net in the box. Json.net is a very performant and complete json serializer.

    In terms of architecture and performance, my choice is Webapi.
    Having to choose between 1 and 2, I would prefer 2 as it would be easily migrated to Webapi.


    Raffaele Rialdi  http://www.iamraf.net
    Weblog: http://blogs.ugidotnet.org/raffaele
    Microsoft MVP profile https://mvp.support.microsoft.com/profile/raffaele
    UGIdotNET - http://www.ugidotnet.org/


    Raffaele Rialdi [MVP] My articles and videos: http://www.iamraf.net Italian blog: http://blogs.ugidotnet.org/raffaele
    Sunday, May 13, 2012 6:26 PM
  • Hi,

    Thanks again. I can understand Web API is the most matured version of REST in Microsoft stack. But my question is, whether the approach 1 and 2 both follows  Microsoft's earlier REST architecture? Are both of them  really follow the same Architecture?

    Regards

    ronit_rc

    Sunday, May 13, 2012 6:36 PM
  • ronit_rc wrote:


    Hi,

    Thanks again. I can understand Web API is the most matured version of REST in Microsoft stack. But my question is, whether the approach 1 and 2 both follows  Microsoft's earlier REST architecture? Are both of them  really follow the same Architecture?

    Regards

    You're welcome.
    Architecture really depdends on how you structure your system. You can write a perfect rest-hypermedia architecture using a bare asp.net httphandler or even sockets.
    On the other side, even with webapi (as the most current technology rest-oriented) you can write services that are far-away from being restful.

    Those technologies (WCF-Rest/JsonResult/WebAPI) are simply a convenienet way for you to avoid writing tons of code (most of it would be boilerplate).

    Probably wcf/rest, from a technology perspective, does make more sense if you want to expose data in both soap and rest mode. But at this point I would ask if it really makes sense as SOA architecture and REST architecture do not overlap at all (maybe only in simple CRUD scenarios).


    Raffaele Rialdi  http://www.iamraf.net
    Weblog: http://blogs.ugidotnet.org/raffaele
    Microsoft MVP profile https://mvp.support.microsoft.com/profile/raffaele
    UGIdotNET - http://www.ugidotnet.org/


    Raffaele Rialdi [MVP] My articles and videos: http://www.iamraf.net Italian blog: http://blogs.ugidotnet.org/raffaele
    Sunday, May 13, 2012 7:04 PM
  • Hi,

    Thanks again.

    Finallay, I have 2 questions:

    1) I am having a System in place,developed in Silverlight, which uses WCF services in backend. Now, I want to migrate the project using some other web technology, in Microsoft Web stack (ASP.NET,ASP.NET MVC etc.). I n this sceanario, which solution is best? If I expose the WCF services in REST way and consume the the same ASPX/HTML client, I can reuse the services, which saves a huge dev. effort. Please suggest.

    2) Say, I want to develop  a System, where data entry parts will be handled using Windows Form and Reporting/Approval part will be handled in Web. The application will be distributed. In this scanario, should we use WCF or Web API? I beleive in order to consume Web API in Windows Form, we need to POST the request to URI. Is it a good option? Please suggest.

    Regards

    ronit_rc 

    Monday, May 14, 2012 5:44 AM
  • ronit_rc wrote:


    1) I am having a System in place,developed in Silverlight, which uses WCF services in backend. Now, I want to migrate the project using some other web technology, in Microsoft Web stack (ASP.NET,ASP.NET MVC etc.). I n this sceanario, which solution is best? If I expose the WCF services in REST way and consume the the same ASPX/HTML client, I can reuse the services, which saves a huge dev. effort. Please suggest.

    The fastest solution is to change the endpoint for RIA to json (now it's supported) and consume data via jquery.
    This new library has been renamed to upshot and you can read about it here:
    http://www.asp.net/single-page-application
    http://www.asp.net/single-page-application/an-introduction-to-spa/overview/landingpage

    As a longer term, I would migrate all the solution using webapi. Depending on your code it could be straightforward or a difficult task.
     > 2) Say, I want to develop  a System, where data entry parts will be handled

    using Windows Form and Reporting/Approval part will be handled in Web. The application will be distributed. In this scanario, should we use WCF or Web API? I beleive in order to consume Web API in Windows Form, we need to POST the request to URI. Is it a good option? Please suggest.

    Sounds like a CRUD with a machine state, a solution that can be easily afforded with both SOA and REST.
    The main difference in terms of application lifecycle is versioning.
    The REST solution is more flexible (but on the other side the clients should be ready to handle 404 endpoints as the server side evolves).
    The SOA solution is more 'rpc' and suitable when, in addition to the pure CRUD, you have some other stuff to do.

    Developing CRUD with Webapi is really easy and a matter of few minutes.
    From Windows Forms you have HttpClient class and DataContractSerializer (or DataJsonContractSerializer). In a few lines you can CRUD your data using all the REST classical verbs (GET/PUT/POST/DELETE/PATCH)


    Raffaele Rialdi  http://www.iamraf.net
    Weblog: http://blogs.ugidotnet.org/raffaele
    Microsoft MVP profile https://mvp.support.microsoft.com/profile/raffaele
    UGIdotNET - http://www.ugidotnet.org/


    Raffaele Rialdi [MVP] My articles and videos: http://www.iamraf.net Italian blog: http://blogs.ugidotnet.org/raffaele
    • Marked as answer by ronit_rc Monday, May 14, 2012 9:40 AM
    Monday, May 14, 2012 7:34 AM
  • Hi,

    Thanks a lot for your help.

    Regards

    ronit_rc

    Monday, May 14, 2012 9:40 AM