Join the google group or follow @demisbellot and @ServiceStack for twitter updates. You can also join a growing crowd of ServiceStack users on JabbR if you want to chat.
Service Stack is a high-performance .NET web services framework (including a number of high-performance sub-components: see below) that simplifies the development of XML, JSON, JSV and WCF SOAP Web Services. For more info check out servicestack.net.
This example is also available as a stand-alone integration test:
//Web Service Host Configuration
public class AppHost : AppHostHttpListenerBase
{
public AppHost() : base("TODOs Tests", typeof(Todo).Assembly) {}
public override void Configure(Container container)
{
container.Register(new TodoRepository());
}
}
//REST Resource DTO
[Route("/todos")]
[Route("/todos/{Ids}")]
public class Todos : IReturn<List<Todo>>
{
public long[] Ids { get; set; }
public Todos(params long[] ids)
{
this.Ids = ids;
}
}
[Route("/todos", "POST")]
[Route("/todos/{Id}", "PUT")]
public class Todo : IReturn<Todo>
{
public long Id { get; set; }
public string Content { get; set; }
public int Order { get; set; }
public bool Done { get; set; }
}
public class TodosService : Service
{
public TodoRepository Repository { get; set; } //Injected by IOC
public object Get(Todos request)
{
return request.Ids.IsEmpty()
? Repository.GetAll()
: Repository.GetByIds(request.Ids);
}
public object Post(Todo todo)
{
return Repository.Store(todo);
}
public object Put(Todo todo)
{
return Repository.Store(todo);
}
public void Delete(Todos request)
{
Repository.DeleteByIds(request.Ids);
}
}
//no code-gen required, can re-use above DTO's
var restClient = new JsonServiceClient(BaseUri);
List<Todo> all = restClient.Get(new Todos()); // Count = 0
var todo = restClient.Post(
new Todo { Content = "New TODO", Order = 1 }); // todo.Id = 1
all = restClient.Get(new Todos()); // Count = 1
todo.Content = "Updated TODO";
todo = restClient.Put(todo); // todo.Content = Updated TODO
restClient.Delete(new Todos(todo.Id));
all = restClient.Get(new Todos()); // Count = 0
$.getJSON(baseUri, function(todos) {
alert(todos.length == 1);
});
Calling the TODO REST service from Dart JsonClient
var client = new JsonClient(baseUri);
client.todos()
.then((todos) => alert(todos.length == 1) );
That's all the application code required to create a simple REST web service.
##Live Demo of Backbone TODO app (running on Linux/MONO):
http://www.servicestack.net/Backbone.Todos/
Preview links using just the above code sample with (live demo running on Linux):
ServiceStack's strong-typed nature allows it to infer a greater intelligence of your web services and is able to provide a host of functionality for free, out of the box without any configuration required:
-
Host on different formats and endpoints: XML, JSON, JSV, CSV
-
A HTML5 Report format to view your webservics data in a human-friendly view
-
An auto generated api metadata page, with links to your web service XSD's and WSDL's
If you have NuGet installed, the easiest way to get started is to install ServiceStack via NuGet:
ServiceStack with Razor Support: Create an empty ASP.NET Web or Console Application and (.NET 4.0+)
ServiceStack binaries only: Minimal installation of ServiceStack containing only the core-binaries (.NET 3.5+)
If you just want ServiceStack hosted at /
- Create an empty ASP.NET Web Application and
Otherwise if you want to host ServiceStack Side-by-Side with MVC: Hosted at /api
- Create an empty MVC Web Application and
To help get started you should also download the ServiceStack.Examples projects (includes dlls, demos and starter templates):
If you prefer not to use NuGet and just want to download the latest release binaries get them at:
Alternatively if you want keep up with the latest version you can always use the power of Git :)
git clone git://github.com/ServiceStack/ServiceStack.git
Release notes for major releases
Developed in the modern age, Service Stack provides an alternate, cleaner POCO-driven way of creating web services, featuring:
Unlike other web services frameworks ServiceStack let's you develop web services using strongly-typed models and DTO's. This lets ServiceStack and other tools to have a greater intelligence about your services allowing:
- Multiple serialization formats (JSON, XML, JSV and SOAP with extensible plugin model for more)
- A single re-usable C# Generic Client (In JSON, JSV, XML and SOAP flavours) that can talk to all your services.
- Re-use your Web Service DTOs (i.e. no code-gen) on your client applications so you're never out-of-sync
- Automatic serialization of Exceptions in your DTOs ResponseStatus
- The possibility of a base class for all your services to put high-level application logic (i.e security, logging, etc)
- Highly testable, your in-memory unit tests for your service can also be used as integration tests
- Built-in rolling web service error logging (if Redis is Configured in your AppHost)
- Rich REST and HTML support on all web services with x-www-form-urlencoded & multipart/form-data (i.e. FORM posts and file uploads)
Service Stack was heavily influenced by Martin Fowlers Data Transfer Object Pattern:
When you're working with a remote interface, such as Remote Facade (388), each call to it is expensive. As a result you need to reduce the number of calls, and that means that you need to transfer more data with each call. One way to do this is to use lots of parameters. However, this is often awkward to program - indeed, it's often impossible with languages such as Java that return only a single value.
The solution is to create a Data Transfer Object that can hold all the data for the call. It needs to be serializable to go across the connection. Usually an assembler is used on the server side to transfer data between the DTO and any domain objects.
The Request and Response DTO's used to define web services in ServiceStack are standard DataContract
POCO's while the implementation just needs to inherit from a testable and dependency-free IService<TRequestDto>
. As a bonus for keeping your DTO's in a separate dependency-free .dll, you're able to re-use them in your C#/.NET clients providing a strongly-typed API without any code-gen what-so-ever. Also your DTO's define everything Service Stack does not pollute your web services with any additional custom artefacts or markup.
Service Stack re-uses the custom artefacts above and with zero-config and without imposing any extra burden on the developer adds discover-ability and provides hosting of your web service on a number of different physical end-points which as of today includes: XML (+REST), JSON (+REST), JSV (+REST) and SOAP 1.1 / SOAP 1.2.
Unfortunately this best-practices convention is effectively discouraged by Microsoft's WCF SOAP Web Services framework as they encourage you to develop API-specific RPC method calls by mandating the use method signatures to define your web services API. This results in less re-usable, more client-sepcfic APIs that encourages more remote method calls.
Unhappy with this perceived anit-pattern in WCF, ServiceStack was born providing a Web Sevice framework that embraces best-practices for calling remote services, using config-free, convention-based DTO's.
Your application logic should not be tied to a third party vendor's web service host platform. In Service Stack they're not, your web service implementations are host and end-point ignorant, dependency-free and can be unit-tested independently of ASP.NET, Service Stack or its IOC.
Without any code changes unit tests written can be re-used and run as integration tests simply by switching the IServiceClient used to point to a configured end-point host.
Configured to auto-wire all of your web services with your registered dependencies. Funq was chosen for it's high-performance, low footprint and intuitive full-featured minimalistic API.
Entire POCO types are used to define the request and response DTO's to promote the creation well-defined coarse-grained web services. Message-based interfaces are best-practices when dealing with out-of-process calls as they are can batch more work using less network calls and are ultimately more re-usable as the same operation can be called using different calling semantics. This is in stark contrast to WCF's Operation or Service contracts which encourage RPC-style, application-specific web services by using method signatures to define each operation.
As it stands in general-purpose computing today, there is nothing more expensive you can do than a remote network call. Although easier for the newbie developer, by using methods to define web service operations, WCF is promoting bad-practices by encouraging them to design and treat web-service calls like normal function calls even though they are millions of times slower. Especially at the app-server tier, nothing hurts performance and scalability of your client and server than multiple dependent and synchronous web service calls.
Batch-full, message-based web services are ideally suited in development of SOA services as they result in fewer, richer and more re-usable web services that need to be maintained. RPC-style services normally manifest themselves from a client perspective that is the result of the requirements of a single applications data access scenario. Single applications come and go over time while your data and services are poised to hang around for the longer term. Ideally you want to think about the definition of your web service from a services and data perspective and how you can expose your data so it is more re-usable by a number of your clients.
With Mono on Linux now reaching full-maturity, Service Stack runs on .NET or Linux with Mono and can either be hosted inside an ASP.NET Web Application, Windows service or Console application running in or independently of a Web Server.
No coupling between the transport's endpoint and your web service's payload. You can re-use your existing strongly-typed web service DTO's with any .NET client using the available Soap, Xml and Json Service Clients - giving you a strongly-typed API while at the same time avoiding the need for any generated code.
- The most popular web service endpoints are configured by default. With no extra effort, each new web service created is immediately available and discoverable on the following end points:
- View the Service Stack endpoints page for our recommendations on which endpoint to use and when.
Also included in ServiceStack are libraries that are useful in the development of high performance web services:
-
ServiceStack.Text - The home of ServiceStack's JSON and JSV text serializers, the fastest text serializers for .NET
- JsonSerializer - The fastest JSON Serializer for .NET. Over 3 times faster than other .NET JSON serialisers.
- TypeSerializer - The JSV-format, a fast, compact text serializer that is very resilient to schema changes and is:
- 3.5x quicker and 2.6x smaller than the .NET XML DataContractSerializer and
- 5.3x quicker and 1.3x smaller than the .NET JSON DataContractSerializer - view the detailed benchmarks
-
ServiceStack.Redis - An API complete C# Redis client with native support for persisting C# POCO objects.
- You can find links to the latest windows builds at the end of this StackOverflow Answer on Redis
- Redis Admin UI - An Ajax GUI admin tool to help visualize your Redis data.
-
OrmLite - A convention-based, configuration free lightweight ORM that uses attributes from DataAnnotations to infer the table schema. Currently supports both Sqlite and SqlServer.
-
Caching - A common interface for caching with providers for:
- Memcached
- In Memory Cache
- Redis
- Follow @demisbellot or @ServiceStack for updates.
Service Stack is under continuous improvement and is always adding features that are useful for high-performance, scalable and resilient web service scenarios. See the trello board to get information about the current project status and upcoming features.
Similar Open source .NET projects for developing or accessing web services include:
- Nancy Fx - A Sinatra-inspired lightweight Web Framework for .NET:
- Fubu MVC - A "Front Controller" pattern-style MVC framework designed for use in web applications built on ASP.NET:
- Rest Sharp - An open source REST client for .NET
ServiceStack includes source code of the great libraries below for some of its core functionality. Each library is released under its respective licence:
- Mono (License)
- Funq IOC (License)
- Fluent Validation (License)
- Mini Profiler (License)
- Dapper (License)
- TweetStation's OAuth library (License)
- MarkdownSharp (License)
- MarkdownDeep (License)
http://www.jetbrains.com/profiler/
A big thanks to GitHub and all of ServiceStack's contributors:
- bman654 (Brandon Wallace)
- Iristyle (Ethan Brown)
- superlogical (Jake Scott)
- itamar82
- chadwackerman
- derfsplat
- JohnACarruthers (John Carruthers)
- mvitorino (Miguel Vitorino)
- bsiegel (Brandon Siegel)
- mdavid (M. David Peterson)
- lhaussknecht (Louis Haussknecht)
- grendello (Marek Habersack)
- SteveDunn (Steve Dunn)
- kcherenkov (Konstantin Cherenkov)
- timryan (Tim Ryan)
- letssellsomebananas (Tymek Majewski)
- danbarua (Dan Barua)
- JonCanning (Jon Canning)
- paegun (James Gorlick)
- pvasek (pvasek)
- derfsplat (derfsplat)
- justinrolston (Justin Rolston)
- danmiser (Dan Miser)
- danatkinson (Dan Atkinson)
- brainless83 (Thomas Grassauer)
- angelcolmenares (angel colmenares)
- dbeattie71 (Derek Beattie)
- danielwertheim (Daniel Wertheim)
- greghroberts (Gregh Roberts)
- int03 (Selim Selçuk)
- andidog (AndiDog)
- chuckb (chuckb)
- niemyjski (Blake Niemyjski)
- mj1856 (Matt Johnson)
- matthieugd (Matthieu)
- tomaszkubacki (Tomasz Kubacki)
- e11137 (Rogelio Canedo)
- davrot (David Roth)
- meebey (Mirco Bauer)
- codedemonuk (Pervez Choudhury)
- jrosskopf (Joachim Rosskopf)
- friism (Michael Friis)
- mp3125
- aurimas86
- parnham (Dan Parnham)
- yeurch (Richard Fawcett)
- damianh (Damian Hickey)
- freeman (Michel Rasschaert)
- kvervo (Kvervo)
- pauldbau (Paul Du Bois)
- justinpihony (Justin Pihony)
- bokmadsen (Bo Kingo Damgaard)
- dragan (Dale Ragan)
- sneal (Shawn Neal)
- johnsheehan (John Sheehan)
- jschlicht (Jared Schlicht)
- kumarnitin (Nitin Kumar)
- DavidChristiansen (David Christiansen)
- PaulECoyote (Paul Evans)
- kongo2002 (Gregor Uhlenheuer)
- BrannonKing (Brannon King)
- alexandrerocco (Alexandre Rocco)
- cbarbara
- assaframan (Assaf Raman)
- csakshaug (Christian Sakshaug)
- johnman
- jarroda
- ssboisen (Simon Skov Boisen)
- paulduran (Paul Duran)
- pruiz (Pablo Ruiz García)
- fantasticjamieburns
- pseabury
- kevingessner (Kevin Gessner)
- iskomorokh (Igor Skomorokh)
- royjacobs (Roy Jacobs)
- robertmircea (Robert Mircea)
- markswiatek (Mark Swiatek)
- flq (Frank Quednau)
- ashd (Ash D)
- thanhhh
- algra (Alexey Gravanov)
- jimschubert (Jim Schubert)
- gkathire
- mikaelwaltersson (Mikael Waltersson)
- asunar (Alper)
- chucksavage (Chuck Savage)
- sashagit (Sasha)
- froyke (Froyke)
- dbhobbs (Daniel Hobbs)
- bculberson (Brad Culberson)
- awr (Andrew)
- pingvinen (Patrick)
- citndev (Sebastien Curutchet)
- cyberprune
- jorbor (Jordan Hayashi)
- bojanv55
- i-e-b (Iain Ballard)
- pietervp (Pieter Van Parys)
- franklinwise
- ckasabula (Chuck Kasabula)
- dortzur (Dor Tzur)
- allenarthurgay (Allen Gay)
- vansha (Ivan Korneliuk)
- aaronlerch (Aaron Lerch)
- glikoz
- danielcrenna (Daniel Crenna)
- stevegraygh (Steve Graygh)
- jrmitch120 (Jeff Mitchell)
- manuelnelson (Manuel Nelson)
- babcca (Petr Babicka)
- jgeurts (Jim Geurts)
- driis (Dennis Riis)
- gshackles (Greg Shackles)
- jsonmez (John Sonmez)
- dchurchland (David Churchland)
- softwx (Steve Hatchett)
- ggeurts (Gerke Geurts)
- andrewrissing (Andrew Rissing)
- jjavery (James Javery)
- suremaker (Wojtek)
- cheesebaron (Tomasz Cielecki)
- mikkelfish (Mikkel Fishman)
- johngibb (John Gibb)
Runs on both Mono and .NET 3.5. (Live preview hosted on Mono / CentOS)