301

I want to write a new REST style API and have looked at ServiceStack and quite like it. However, I have seen that Microsoft has released the ASP.Net Web API project as part of the new MVC 4 beta. Has anyone looked at the new Web API project? Can you give any pros/cons of each system?

Jehof
  • 34,674
  • 10
  • 123
  • 155
flipchart
  • 6,548
  • 4
  • 28
  • 53

5 Answers5

390

They have very similar use-cases, as the lead maintainer for the ServiceStack project I have a good insight into ServiceStack's advantages and the many natural benefits of its message-based design.

ServiceStack has been around since 2008 as an OSS-run project from its inception with a single goal of promoting the correct design and implementation of friction-free remote services.

Simple and Elegant Design

In its pursuit for ultimate simplicity, it's built around a simple and elegant core - with most of its features naturally binding to your models, not your controllers - which is what MVC, WebApi does (as well as every other Web Service Framework Microsoft has produced).

Adopting a message-based design offers a superior approach for remote services, in that they promote more extensible and less brittle services, simplifies access and calling patterns, and contain many other natural benefits you get for free.

As a core mission, we fight complexity at every stage, aiming to keep an invisible and non-intrusive API and avoid introducing any new concepts or artificial constructs that aren't already familiar to .NET or web service developers today.

As an example your IService<T> service implementation is just a standard C# class with auto-wired dependencies. Thin and lightweight wrappers are used to provide a consistent and unified API around the core run-time IHttpRequest and IHttpResponse types. They also allow access to underlying ASP.NET or HttpListener's Request and Response classes so you're never restricted when using ServiceStack.

Contrasted with WCF and WebApi

Here's a brief overview of the contrasting API styles that ServiceStack and WCF promote. WebApi is different to WCF in that it encourages REST-ful API design. As for examples between the 2, this is the only known example I have with the same service written in both ServiceStack and WebApi.

Best Practices remote services

ServiceStack has a primary focus on simplicity, performance and in promoting web/remote service best-practices centered around embracing Martin Fowlers remote-service design patterns in as idiomatic C# as possible:

  • The Facade Pattern - Which suggests the usage of batchful, coarse-grained interfaces when ever you communicate across process boundaries.

  • The DTO pattern (MSDN) - Dictating the use of special-purpose POCOs to generate the wire format of your web services responses.

  • The Gateway Pattern (MSDN) to encapsulate your client and server communications between the Client Gateway / DTO models and Service Interface tiers.

These patterns ensure a clean separation of concerns and a friction-free iterative dev experience.

Empowering your services

A ServiceStack web service at its core is centered around a dependency-free and auto-wired pure C# IService<T> interface that gives you complete freedom to define your web service contract with your own Request and Response DTOs using clean POCOs - rendering ServiceStack's API practically invisible and non-invasive, i.e. it's trivial to extract your C# services logic and run it outside of a ServiceStack host.

This gist is a good example of what you get with just 1 C# .cs class in ServiceStack:

  • Metadata pages for all registered formats
    • With links to WSDLs, XSDs and C# client examples
  • Human friendly HTML report view
    • A single self-contained html page snapshot (i.e. no external refs). Includes embedded JSON web service response - allows programmatic access to data snapshots.
  • Built-in Mini Profiler (port of the excellent MVC Mini Profiler)
    • Includes Sql Profiling
  • JSON/JSONP, XML, JSV, CSV and SOAP end-points

The RestServiceBase and ServiceBase classes are intended to host your custom C# logic for maximum potential re-use as possible, e.g. Its DTO-first design trivially allows for deferred and proxied execution where your same C# Service can also be hosted and executed in an MQ Host which is what happens when you register an IMessageService like the RedisMQ host and call your service via the /asynconeway endpoint (i.e. client.SendOneWay() in C# Clients)

You can also easily delegate and create composite services using the base.ResolveService<T>() method which returns an auto-wired instance of the selected service as seen in the Nortwind CustomerDetails Service example:

var ordersService = base.ResolveService<OrdersService>();
var ordersResponse = (OrdersResponse)ordersService.Get(
    new Orders { CustomerId = customer.Id });

Return plain C# objects

For the most part ServiceStack will serialize most C# objects as expected - here's a list of possible return types (from this answer):

  • Any DTO object -> serialized to Response ContentType
  • HttpResult, HttpError, CompressedResult (IHttpResult) for Customized HTTP response

The following types are not converted and get written directly to the Response Stream:

  • String
  • Stream
  • IStreamWriter
  • byte[] - with the application/octet-stream Content Type.

An example of the Custom HTTP headers support can be seen by this CORS example where you can configure HTTP Headers globally or on a per-service basis.

HTML Support

There are multiple options for returning HTML in ServiceStack that is explained in detail here.

Includes fastest text and binary serializers for .NET

Resilient and fast serializers are of primary importance in an API to ensure fast response times and a versionable API which doesn't break existing clients which is why ServiceStack includes the fastest text serializers for .NET with a NuGet option to enable @marcgravell's Protocol Buffers (.NET's fastest binary serializer).

ServiceStack's text serializers are very resilient and can withstand extreme versioning without error.

Friction-free dev experience End-to-End

ServiceStack's opinionated nature allows for a fast, typed, terse web service API end-to-end with built-in support for Sync/Async C#/.NET and Async Silverlight clients without any code-gen:

Sync C# Example

var response = client.Send<HelloResponse>(new Hello { Name = "World!" });

Async C# Example

client.SendAsync<HelloResponse>(new Hello { Name = "World!" },
    r => Console.WriteLine(r.Result), (r, ex) => { throw ex; });

As it just returns pure JSON it's also trivially consumed with other HTTP Clients, e.g. JS client example using jQuery:

$.getJSON("http://localhost/Backbone.Todo/todos", function(todos) {
    alert(todos.length == 1);
});

Highly testable

All C#/.NET ServiceClients share the same interfaces which make them highly testable and swappable to the point where you can have the same unit test also serve as an XML, JSON, JSV, SOAP Integration Test.

Rich Validation and Error Handling built-in

In its mission to provide a friciton-free and clean dev experience, ServiceStack also includes typed validation and error handling built-in where throwing an C# Exception or using its built-in Fluent validation provides clients structured, typed errors easily accessible on web service clients, e.g:

try {
    var client = new JsonServiceClient(BaseUri);
    var response = client.Send<UserResponse>(new User());
} catch (WebServiceException webEx) {
    /*
      webEx.StatusCode  = 400
      webEx.ErrorCode   = ArgumentNullException
      webEx.Message     = Value cannot be null. Parameter name: Name
      webEx.StackTrace  = (your Server Exception StackTrace - if DebugMode is enabled)
      webEx.ResponseDto = (your populated Response DTO)
      webEx.ResponseStatus   = (your populated Response Status DTO)
      webEx.GetFieldErrors() = (individual errors for each field if any)
    */
}

To make it trivial to consume errors in JavaScript, you can use the lightweight ss-validation.js JavaScript library to trivially bind your response errors to your HTML form fields with a single line of code. The SocialBootstrapApi example project provides a good demo of this.

Rich Integration with ASP.NET and MVC

The ServiceStack MVC PowerPack re-writes and fixes a lot of the ails of ASP.NET and MVC with replacements for its crippling Session and Caching XML-encumbered ASP.NET providers with its own clean and dependency-free implementation of ICacheClient and ISession APIs.

ServiceStack also includes a newer and cleaner authentication and autorization provider model with a number of different AuthProviders in-built:

  • Credentials - For authenticating with username/password credentials by posting to the /auth/credentials service
  • Basic Auth - Allowing users to authenticate with Basic Authentication
  • Twitter OAuth - Allow users to Register and Authenticate with Twitter
  • Facebook OAuth - Allow users to Register and Authenticate with Facebook

The Authentication module is entirely optional and is built-on the clean ICacheClient / ISession APIs and OrmLite which allows your Sessions to be stored in Memory, Redis or Memcached and your UserAuth info persisted in OrmLite's supported RDBMS's of SQLServer, MySql, PostgreSQL, Sqlite as well as Redis data-store or InMemory (useful for dev/testing).

Great Documentation

ServiceStack is very well documented where most of the information about the framework is hosted on the GitHub wiki. Documentation for other parts of the framework (e.g. Serializers, Redis, OrmLite) can be found on servicestack.net/docs/

The ServiceStack.Examples Project provides the source code for all of ServiceStack's live demos and Starter Templates whilst the SocialBoostsrapApi project provides a great starting point of developing a Backbone.js Single Page App with ServiceStack and MVC based on Twitters Bootstrap template.

In addition to the above a treasure trove of information is contained within the Google Group which has expanded quite considerably in recent years.

Runs Everywhere

ServiceStack is a .NET 3.5 framework that runs on ASP.NET and HttpListener hosts and can be hosted on either .NET or Mono (trivia: www.servicestack.net is powered by CentOS/Mono). This allows your ServiceStack web services to be hosted on either:

Windows with .NET 3.5 & 4.0

Linux/OSX with Mono

  • Apache + mod_mono
  • Nginx + MonoFastCGI
  • XSP
  • Console App

Developed with the Open Source development model

ServiceStack is a strong believer of the Open Source development model where it is actively developed in the open and has always been hosted under a liberal OSS licence (New BSD) since its inception. As of today it has received contributions from more than 47 developers and it currently stands at the 3rd most watched C# project on GitHub.

Disadvantages

I believe the biggest disadvantage is the same for most other OSS .NET projects where it wasn't developed (or even listed as an available option) by Microsoft. This means it's rarely ever the first choice when evaluating a framework. Most adopters will only evaluate ServiceStack as a last resort, where they're either frustrated with the imposed friction and brittleness of WCF or the performance of the preferred Microsoft Stack.

Feedback and Community Resources

ServiceStack has been very well received with positive feedback provided by most people who have evaluated it as visible by the positive sentiment in the mailing group. As of this year the @ServiceStack twitter account has been tracking mentions and feedback in its favorites.

The Community Resources wiki page is a good place to find out more about ServiceStack in the wild with links to Blog Posts, Pod Casts, Presentations, Gists and more.

Community
  • 1
  • 1
mythz
  • 141,670
  • 29
  • 246
  • 390
  • 1
    In addition to the JSON/JSONP, XML, JSV, CSV and SOAP end-points is there an easy way to add HTML (razor) view responses? – Chris Marisic Mar 14 '12 at 20:13
  • 4
    I am curious as to whether there are any benchmarks comparing ServiceStack to MVC/WebAPI. I would think it would be a bit faster. – AlexGad Mar 15 '12 at 02:26
  • 30
    As someone who has tried using WCF, webapi and now ServiceStack, stick with ServiceStack. 1) WCF is needlessly too complex for most. It's the old "let's solve all problems" delima. 2) web-api is too new. Wait for the final release. It doesn't even support posts of muli-part forms. The code is in a state of flux. I wouldn't run commercial apps on it. BTW, this question shouldn't be closed. – Michael Silver Jul 10 '12 at 19:51
  • 14
    Could you please edit this for the ASP.NET WebAPI that was just released. – Blake Niemyjski Aug 23 '12 at 19:41
  • 3
    http://www.servicestack.net/ SS has updated their slides included WebAPI comparison. – Tom Oct 18 '12 at 16:31
  • 27
    Please make your website more user-friendly. This seems like a great tool. But the your site is confusing. It's no clear what the project is and what it aims to solve. In contrast, this answer is fantastic. – Kugel Nov 28 '12 at 12:25
  • 2
    Agree - the the ServiceStack website is confusing and disjointed. It lets down the project. But answer is upvoted - it's excellent. – NickG Jan 17 '13 at 15:16
  • 84
    This really doesn't seem to be much of a comparison with Web API. It makes sense - at the time of the answer, Web API was brand new. This is not the case anymore. I would really love to see an actual breakdown and I fear this answer is out of date. – George Mauer Mar 21 '13 at 23:58
  • 10
    Would love to see a detailed comparison though, instead of just a pro-list of ServiceStack. Does Web API share some of the good stuff of Service Stack, are there pieces it does better and ServiceStack is planning to take over? Pieces that are equal? How about the new releases of Web API versus the first release – David Cumps Jun 11 '13 at 20:55
  • 3
    I realize this was written over a year ago. I’ll give my view at this point after seeing how both platforms have progressed. At this point Web API isn’t so new. The documentation has started to finally catch up with the product. So grabbing a book that you can understand, and or find a website to dive into more detail. In addition to this a lot of what you learned in MVC and what you are currently doing transitions nicely. So while ServiceStack is really nice it’s really more of an investment to switch, plus more work to train, considering you really only have the documentation on the site. – LCarter Aug 14 '13 at 22:38
  • 3
    I spent couple of days trying to create REST JSON service using WCF. I miserably failed. With ServiceStack I had it up and running in one hour. Just saying... – Vasyl Boroviak Aug 20 '13 at 04:40
  • 36
    It may be worth pointing out that ServiceStack is moving to a commercial-only/binary distribution as of v4.0. See Demis's [Google+ post](https://plus.google.com/app/basic/stream/z12tfvoackvnx1xzd04cfrirpvybu1nje54) for details. – Nick Jones Aug 27 '13 at 13:09
  • 10
    I really like the ideas behind ServiceStack, but commercializing it is unethical given that the project boasts having over 220 contributes. What do the contributors get for their efforts? Do they get royalties? At least Microsoft pays their developers and does walk off with their code without writing them a check. – ATL_DEV Sep 30 '13 at 12:50
  • 2
    I love some ServiceStack, but a huge disadvantage is that OWIN is still not officially supported. – Ronnie Overby Oct 08 '13 at 14:27
  • 1
    Async isn't really supported either. The client "Async" methods don't return Task.The server side doesn't seem to know anything about Tasks at all. If I use 'async/await' what context will be used? Finally, there is no way to execute a long running task. All these are available in Web API – Panagiotis Kanavos Oct 22 '13 at 05:57
  • 2
    @PanagiotisKanavos v4 has seen all projects upgraded to .NET 4.0 which now supports both [Server-Side Async](https://plus.google.com/106787359118990653189/posts/KoUyRbmYoPJ) and [Client-Side Async/Await](https://plus.google.com/106787359118990653189/posts/NxHUpV1sg1d). You also don't need special support for long-running tasks, just don't close (and keep writing to) the response in either an async service or your own custom registered IHttpHandler. – mythz Oct 22 '13 at 06:18
  • @mythz What does writing to the response have to do with long-running tasks, eg. like calling multiple external services and paying for air tickets? With ASP.NET I have RegisterLongRunningTask to do this, with SS I have to find workarounds and lose the benefits of thread pooling. – Panagiotis Kanavos Oct 22 '13 at 06:44
  • @PanagiotisKanavos Don't understand the relevance of that analogy. I explained how to can create long-running services. If you wan't to have services running on long-running background threads you can just use an MQ host, which lets you call existing services running on a configurable pool of background threads. – mythz Oct 22 '13 at 06:51
  • 1
    I like the idea of Service Stack, however I need to build an api now. I could use Web API, or wait for version 4, when is it out? It looks like 4 will break any work done using version 3, so is it worth waiting or not? – Mark Redman Nov 02 '13 at 09:32
  • @MarkRedman v4 is a big departure from v3, although development of v4-beta is mostly complete with the binary packages already available on [MyGet at these instructions](http://bit.ly/GY61IH). It includes an evaluation limit that expires at Dec 31 which needs to updated before then (i.e. when v4-beta is officially released). The ETA for v4-beta is at the end of this month as there's still a number of docs and support systems that need to be put in place before v4-beta can be released and supported, but these shouldn't affect the user-facing API which have effectively been finalized. – mythz Nov 02 '13 at 12:44
  • @mythz: thanks! will have a look, and is there any ballpark pricing? – Mark Redman Nov 02 '13 at 12:45
  • @MarkRedman Pricing hasn't been finalized yet, but [the expected licensing models and ball-park pricing and have been discussed on this thread](https://plus.google.com/110206964695196648971/posts/TAr55EPCGuF). – mythz Nov 02 '13 at 12:51
  • if it couples to the model rather than the controller then how would it support say optional routing at the action level? This is a feature that Web API 2 now supports (i.e., attribute routing). – Phil C Jan 11 '14 at 08:10
  • @Carnotaurus ServiceStack doesn't have RPC actions, it has message handlers which handle incoming messages on either a specific verb or _Any_ verb. Likewise [custom routes](https://github.com/ServiceStack/ServiceStack/wiki/Routing) are defined on either all Verbs or specific ones. Best to read up a bit more about ServiceStack's approach, the [New Api](https://github.com/ServiceStack/ServiceStack/wiki/New-Api) is a good start. – mythz Jan 11 '14 at 09:16
  • 11
    It looks like Service Stack recently changed its licence to a less Commercial Friendly AGPL and started selling commercial licenses. Perhaps this post should be edited to reflect that? Right now it reads like an advertisement for a commercial product. https://github.com/ServiceStack/ServiceStack/blob/master/license.txt – Glenn Apr 09 '14 at 23:52
  • 1
    also .net core web api is super fast! – trees_are_great Aug 29 '17 at 15:05
139

There is a new main difference that needs to be accounted for - ServiceStack is no longer free to use as of v4. Since there is a pretty definitive answer on the SS pro's I wanted to throw a couple out for Web API

Web API

Pro's :

  1. Free to use in your project (provided you have a VS license that allows commercial use)
  2. Extraordinarily high level of free support available from Microsoft and all over the web, including here on StackOverflow.com.
  3. Quickly integrates with other Microsoft technology stacks like ASP.NET MVC which is extremely popular in Microsoft shops
  4. Built in support for RESTful authentication and authorization in your Microsoft stack

Con's :

  1. Doesn't support SOAP

Ancillary Benefits

(Please feel free to leave comments below adding to why Web API has benefits or has pros / cons I can add)

PW Kad
  • 14,953
  • 7
  • 49
  • 82
  • 88
    Not sure that not supporting SOAP is a con – D.Rosado Dec 10 '13 at 12:15
  • 11
    The fact MVC and WebAPI co-exist, is a CON. – Phill Dec 12 '13 at 03:03
  • 1
    I'm confused. How can it be Open-Source, but require you to buy a license to use? – Homr Zodyssey Feb 14 '14 at 16:22
  • The use of open source libraries are governed by their license agreements - https://servicestack.net/terms – PW Kad Feb 14 '14 at 16:33
  • 4
    ServiceStack v3 is still free to use and AFAIK always will be, I don't think anything mythz mentioned is v4 specific. – Kyle Gobel May 03 '14 at 22:13
  • 2
    @kyle back up any v3 related docs while you can then. – PW Kad May 03 '14 at 22:36
  • 1
    @PWKad https://github.com/ServiceStackV3/ServiceStackV3/wiki I don't think this is going anywhere. – Kyle Gobel May 04 '14 at 03:24
  • 2
    You dont need VS to build any .NET code. And VS Express (free) editions are licensed for commercial use. http://stackoverflow.com/questions/13007317/can-i-use-visual-studio-2012-express-edition-for-commercial-use – ScottGuymer Jun 04 '14 at 15:04
  • "Doesn't support soap"? That's like saying WebForms doesn't support MVC - they are unrelated technologies, so a strange statement to make. – NickG Sep 23 '14 at 09:30
  • Had to make up a con. No one can come up with anything better so the placeholder stays – PW Kad Sep 23 '14 at 12:23
  • 14
    Wow, "no longer free" is an understatement. $999 *per developer* for a company with more than ten employees? – Ryan Lundy Dec 22 '14 at 21:36
  • 7
    My biggest reason to switch from Service Stack to Web API is that Service Stack v3 is no longer supported on iOS (using Xamarin) with the new 64 bit architecture requirement. Of course, the updates are in v4 which is the paid version. – SgtRock Feb 17 '15 at 16:03
  • @Phill "coexistance" - Time & tide marching on. Coexistence is becoming less relevant with asp.vNext unifying the two. – EBarr Mar 26 '15 at 13:07
  • I'm aware @EBarr and about time too, Was such a stupid move to have separate products to begin with. We don't have that in Nancy, its 1 framework with proper conneg. – Phill Mar 26 '15 at 13:16
  • @Phil Agree++ The number of questions the split spawned, and simple coding errors that drained time. My impression is that the WebAPI team was allowed more slack to figure out how to decouple from the core .net releases and open source....the rest of ASP.NET platform is now catching up. – EBarr Mar 26 '15 at 13:35
  • The good part of WebApi is that it does not force you to follow a specific approach to design web services. I think it is possible to make message-based apis with ASP.NET WebApi. Take a look at https://github.com/alisabzevari/LiteApi which tries to help create message-based apis with WebApi. – alisabzevari Jun 09 '15 at 07:05
  • 1
    @Phill as of ASP.NET 5 (ASP.NET vNext) they are merging. So one less con ;) – nawfal Jun 24 '15 at 06:24
  • @SgtRock do you need other v4 updates? Do you think you are more productive with ASP.NET Web API? v3 is licensed under BSD, so you will always be allowed to fork it and implement support for iOS, if you think it's worth the effort. – ygormutti Sep 02 '15 at 16:03
  • "Dropping support" for SOAP was a good decision, IMO, as REST obliterates any need of SOAP. REST is by far superior to SOAP. So this should be a pro instead of con. – Thyrador Aug 17 '16 at 09:28
  • 1
    My current project which was developed a few years ago is using ServiceStack 3.9. I now need to create one more service under that project. I am more concerned about the support because v4+ is not free and it appears a bit expensive as we are more than 10 developers. I have MSDN license so I have an option already available (which is obviously ASP.NET Web API) .I am planning to write new services in ASP.NET Web API and as far as features are concerned it seems Web API offers almost everything which ServiceStack does at this stage. – Nirman May 05 '17 at 06:19
21

I can't really say much about ServiceStack, but Web API has a lot of great features and is currently at version 2.

Some of the things you can do with Web API:

  • Self host in an OWIN application (i.e. runs anywhere).
  • Full support for async and await.
  • Good default Templates and tons of open source examples.
  • Used great Json.Net JSON serializer.
  • Rest-ish by default (you'll have to do hypermedia yourself).
  • and more...
J0e3gan
  • 8,740
  • 10
  • 53
  • 80
user3377837
  • 219
  • 2
  • 4
  • 1
    Everything in this list is also present in ServiceStack or can be seen as a con. ServiceStack's JSON serializer, although being less popular, is [much](https://github.com/ServiceStack/ServiceStack/wiki/Real-world-performance) [much](http://mono.servicestack.net/benchmarks/) faster than JSON.NET. OWIN support is unlikely to be implemented because @mythz has strong opinions against this technology, which are fairly sound ([see his comments on this feature request](https://servicestack.uservoice.com/forums/176786-feature-requests/suggestions/4851342-owin-compatible-servicestack)). – ygormutti Sep 02 '15 at 15:56
  • 3
    Looking at OWIN nuget package that has not been upgraded since it was published three years ago, I don't really see the point in all this hype around OWIN support. Looks like people really want to have OWIN because Microsoft once said it is cool. Otherwise you would probably never hear about OWIN at all. Microsoft happily dropped it in favour of their new toy K. This mitigates the argument "Microsoft is behind this so it will live forever" since Microsoft has a strong tendency to kill projects that were heavily pushed by them. – Alexey Zimarev Sep 08 '15 at 10:11
  • Why answer if you have no experience with ServiceStack? – Brian Ogden Aug 25 '17 at 21:22
6

As a customer of ServiceStack here is the pro for ServiceStack most important for me.

https://github.com/ServiceStack/Issues/issues/606

So. Bug found, bug identified, bug fixed. Same day. Extraordinary support!

labilbe
  • 3,501
  • 2
  • 29
  • 34
3

It's been one year that I use SS and it's all great. ORMLite is pure magic. I was able to remap an awfull MySQL DB to integrate in a mobile apps. No change on the database cause it's use with a php backend with another apps...

Mythz is an example regarding support and explanation. It upgraded my knowledge regarding apps design and simplicity on maintenance. Please try it and you will understand.

Also, don't compare SS with WebAPI. It's not enough, SS bring much more to your toolbox. ServiceStack.Text is a great Automapper too.