none
RouteTable vs WebApiRoute vs WebServiceHost2Factory...which one to use & why?

    Question

  • I don’t know why after every release Microsoft is making things so confusing. I trying to develop WCF RESTful service. I’m using VS 2010 Premium with .Net 4. I have downloaded WCF REST Starter Kit and also downloaded WCF REST templates for VS 2010 from visual studio gallery. (WCF REST Service Template 40(CS) ). I have to install the templates from gallary becuase the templates that comes with WCF REST Starter Kit only works with VS 2008

    On all the learning videos & MSDN it says use WebServiceHost2 & WebServiceHost2Factory class for RESTful services, because these classes are specifically designed for REST services and they are included in Microsoft.ServiceModel.Web.dll. Also the examples I have seen so far uses .svc file to host the service.

    So I created a project using the WCF REST Template which I have downloaded from Visual Studio gallery. But it created a service class without using .svc file and also there is no reference to Microsoft.ServiceModel.Web.dll. After little bit of digging and goggling I found its using RouteTable class . Below is the code in global.ascx added by the template

    RouteTable.Routes.Add(new ServiceRoute("Service1", new WebServiceHostFactory(), typeof(Service1)));

    If you note, its not using WebServiceHost2Factory instead its using WebServiceHostFactory.

    These is also new WCF Web API which says "ServiceRoute has a known issue with that causes it to interfere with ASP.NET MVC action link generation. To work around this issue use WebApiRoute in WCF Web API Enhancements instead."

    So now I’m completely confused which is the best way to develop & start WCF RESTful service and what’s the advantage of one over other. I know these approaches will work but which one is preferred approach

    Again, im using VS 2010, .Net 4, IIS 7.5




    • Edited by lax4u Monday, January 09, 2012 8:45 PM
    Monday, January 09, 2012 7:23 PM

Answers

  • Hello, every release aims to provide more features and simplify programming tasks. In general, today it is best to use WCF Web API for non mission critical scenarios, as it is the newest, and reflects the latest requirements most RESTful services need. For mission critical scenarios, it is recommended to stick with .NET 4's built-in REST support, because Web API is a beta product.

    WCF first introduced REST support in .NET 3.5 with the addition of WebHttpBinding and WebGet/Invoke. However, since WCF was originally designed for SOAP's operation oriented architecture and relies heavily on messaging programming model, it was quite difficult to use the .NET 3.5's WCF REST model to build truely (resource oriented) REST services. It was good for exposing existing SOAP operations to non-SOAP protocols, though. A classical example envolves accessing a WCF service from ASP.NET AJAX using JSON.

    WCF REST Starter Kit was designed to simplify programming tasks. For example, it allows you to use a single class WebServiceHost2 to automatically create a REST service, without dealing with WCF concepts such as binding. It removes the requirement of specifying OperationContractAttribute, so at least now you won't be forced to think in an operation oriented way.

    REST Starter Kit can be considered as part of WCF 4 beta. Most of itsfeatures are built into .NET 4 (with some break changes), so you no longer need REST Starter Kit.

    WCF Web API is designed to provide a truely resource oritented programming model. You can do that today with .NET 4's REST support, but it is more difficult. That's where Web API comes.

    Similar to REST Starter Kit, Web API will never be a released product. It will stay in beta. Most of its features are likely to be built into .NET 4.5. But I can't promise you at the moment, and even if it does, you should expect some break changes.


    Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.
    If you have feedback about forum business, please contact msdnmg@microsoft.com. But please do not ask technical questions in the email.
    • Marked as answer by Yi-Lun Luo Monday, January 16, 2012 9:44 AM
    Tuesday, January 10, 2012 12:20 PM

All replies

  • Hello, every release aims to provide more features and simplify programming tasks. In general, today it is best to use WCF Web API for non mission critical scenarios, as it is the newest, and reflects the latest requirements most RESTful services need. For mission critical scenarios, it is recommended to stick with .NET 4's built-in REST support, because Web API is a beta product.

    WCF first introduced REST support in .NET 3.5 with the addition of WebHttpBinding and WebGet/Invoke. However, since WCF was originally designed for SOAP's operation oriented architecture and relies heavily on messaging programming model, it was quite difficult to use the .NET 3.5's WCF REST model to build truely (resource oriented) REST services. It was good for exposing existing SOAP operations to non-SOAP protocols, though. A classical example envolves accessing a WCF service from ASP.NET AJAX using JSON.

    WCF REST Starter Kit was designed to simplify programming tasks. For example, it allows you to use a single class WebServiceHost2 to automatically create a REST service, without dealing with WCF concepts such as binding. It removes the requirement of specifying OperationContractAttribute, so at least now you won't be forced to think in an operation oriented way.

    REST Starter Kit can be considered as part of WCF 4 beta. Most of itsfeatures are built into .NET 4 (with some break changes), so you no longer need REST Starter Kit.

    WCF Web API is designed to provide a truely resource oritented programming model. You can do that today with .NET 4's REST support, but it is more difficult. That's where Web API comes.

    Similar to REST Starter Kit, Web API will never be a released product. It will stay in beta. Most of its features are likely to be built into .NET 4.5. But I can't promise you at the moment, and even if it does, you should expect some break changes.


    Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.
    If you have feedback about forum business, please contact msdnmg@microsoft.com. But please do not ask technical questions in the email.
    • Marked as answer by Yi-Lun Luo Monday, January 16, 2012 9:44 AM
    Tuesday, January 10, 2012 12:20 PM
  • thanks, so there is no need to have Microsoft.ServiceModel.Web.dll refernce in my project?? The dll came withStarter Kit. And if not referncing this dll then where is the [WebHelp] attribute, RequestInterceptor in .net 4. Also, the AdapaterStream class ??


    • Edited by lax4u Tuesday, January 10, 2012 3:59 PM
    Tuesday, January 10, 2012 3:31 PM
  • Yes, you don't need REST Starter Kit any more. AdapaterStream was not bult-into .NET 4. There're some replacements in Web API.
    Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.
    If you have feedback about forum business, please contact msdnmg@microsoft.com. But please do not ask technical questions in the email.
    • Edited by Yi-Lun Luo Wednesday, January 11, 2012 1:53 AM
    Wednesday, January 11, 2012 1:53 AM