Introduction to service stack


Published on

L'OpenSource, che ci crediate o no, è molto attivo anche in ambito .NET. Sono diverse le librerie e i framework che vengono rilasciati a supporto di quanto già possibile fare. In questa sessione vedremo come utilizzare ServiceStack per costruire web services avanzati in modo molto semplice. ServiceStack è questo, e molto altro...

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • Difficult to describe because it does a lof of thingsCross-platform
  • Introduction to service stack

    1. 1. Introduction toServiceStack
    2. 2. Web Services done right,REST services done easy :)Service Stack
    3. 3. Why ServiceStackLa prima alternativa a WCF, MVC e WebAPI◦ Focus su semplicità e velocità◦ Supporto cross-platform con Mono◦ Convention over Configuration◦ No XML Config, No Code-gen◦ POCOs◦ Incoraggia l’utilizzo delle best practices (DTO)◦ Write once, support all◦ XML, JSON, HTML, CSV, JSV
    5. 5. A Stack of ServicesSerializersService EndpointsIoCORMCaching
    6. 6. ComponentsService StackServiceStack.Text ServiceStack.CachingServiceStack.OrmLite ServiceStack.Redis
    7. 7. Simplicity◦C# Model-driven development◦ Definizione delle Web Service API utilizzando DTOs strong-typed◦ No Code-gen◦No Artificial layers or constructs◦ Completo controllo sugli HTTP Headers e sulla serializzazionedell’output◦Endpoint ignorant◦ C# only, code to interfaces and types not specific formats orendpoints◦ C# object IN -> C# object OUT◦No config required
    8. 8. Simplicity - Client◦Same C# client can call any web service at any endpoint◦ Generic C# Service Clients: XML, JSON, JSV andSoap11/Soap12◦ Provides ErrorCode, ErrorMessage from WebServiceException
    9. 9. Speed◦Built on raw IHttpHandlers◦No runtime reflection or regular expressions◦Uses Built-in Funq IOC◦ Funq is 55x faster than Windsor◦Fastest JSON, JSV text serializers for .NET◦ ServiceStack.Text is 3.6x faster DataContractJsonSerializer◦Includes #1 C# Redis Client◦ Redis is the fastest in-memory NoSQL database◦Includes ASP.NET config-free caching providers◦ Memcached◦ Redis◦ In-Memory◦ FileSystem
    10. 10. Encourage Remote Services best practices◦Influenced by Martin Fowlers Data Transfer Object PatternWhen youre working with a remote interface, such as Remote Facade(388), each call to it is expensive. As a result you need to reduce thenumber of calls, and that means that you need to transfer more datawith each call. One way to do this is to use lots of parameters. However,this is often awkward to program - indeed, its often impossible withlanguages such as Java that return only a single value.◦Encourage batch-full, re-usable web services◦ Discourage chatty, client-specific APIs◦Importance of a Coarse-grained, well-defined API◦Simple and flexible serializers with better versioning support◦Decoupling of message from operation and endpoint◦Clean separation of DTO from implementation
    11. 11. Encourage best code practices◦Code-First, Code-Only◦Auto-wired, Built-in IOC◦Decoupled, develop services independently. Easy add/remove◦Develop logic in a DDD clean-room◦Highly testable◦ Same test can be used for Unit or XML, JSON, SOAP, etc Integrationtests◦ HttpListener allows for in-memory integration tests (No HTTPServer reqd.)
    12. 12. Fuse C# and HTTP as DRY as possible◦Develop service using only C# POCO types◦Same service with no config or code-gen◦ Callable via REST, RPC POX/J or SOAP endpoints◦ Callable on any format (XML, JSON, SOAP, JSV, CSV, HTML)◦via HTTP Accept: or ?format=type. JSONP with ?callback=cb◦ Can process HTTP File Upload multipart/form-data◦Strong-typed Request DTO can be populated by:◦ HTTP GET QueryString◦ HTTP POST DTO Content-Type (i.e. XML, JSON, etc)◦ HTTP FORM POST x-www-form-urlencoded◦Can return any of:◦ Any DTO object -> serialized to Response Content-Type◦ HttpResult, HttpError for Customized HTTP response◦ String◦ Stream◦ IStreamWriter
    13. 13. Run everywhere in .NET and MONO◦Supports both ASP.NET and HttpListener hosts:◦Runs on Windows with .NET 3.5 & 4.0◦ IIS 5/6/7 (uses IHttpHandler)◦ VS.NET WebDev server◦ Console App or Windows GUI◦ Windows Service◦Linux/OSX with MONO◦ Apache + mod_mono◦ Nginx + MonoFastCGI◦ XSP◦ Console App◦ Haz demo running inside iOS with MonoTouch :)
    14. 14. demo
    15. 15. ServerArchitecture
    16. 16. Client Architecture
    17. 17. Get ServiceStackNuGet◦ Install-Package ServiceStack◦ Register in web.configStarter Templates◦ Install-Package ServiceStack.Host.Mvc◦ Install-Package ServiceStack.Host.AspNet