Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.

2010 - Basta!: REST mit ASP.NET MVC

REST mit ASP.NET MVC

  • Soyez le premier à commenter

  • Soyez le premier à aimer ceci

2010 - Basta!: REST mit ASP.NET MVC

  1. 1. Daniel Fisher – daniel.fisher@devcoach.com MVC den REST geben
  2. 2. devcoach.com • Leistungen – Beratung und Projektbegleitung – Software-Entwicklung – Training • Technologien – ASP.NET Web Forms & MVC – WCF & WF – Silverlight & MonoTouch • Kunden – Versicherung, Finanzindustrie, Mittelstand, Handel, Kommunikation, Softwarehersteller u.v.a. • Bundesamt für Sicherheit in der Informationstechnologie, • Microsoft • Dresdner Bank • Und Sie? Project Experience Technology Know-how devcoach®
  3. 3. Daniel Fisher • devcoach.com – Mit-Gründer und Geschäftsführer • Justcommunity.de – Mit-Gründer und Vorstand • nrwconf.de – Mit-Gründer und Organisator • netug-niederrhein.de – Mit-Gründer und Leiter • microsoft.com – Business Technology Platform Advisor – Community Leader & Insider (CLIP) – Certified Professional Developer • lennybacon.com – Blog • twitter.com – @lennybacon
  4. 4. Efficient Communication…
  5. 5. Agenda • ASP.NET MVC • REST • REST with ASP.NET MVC • Summary
  6. 6. WHAT IS ASP.NET MVC
  7. 7. Büttenrede Der ViewState is ne falsche Sache - Mir wolle was ganz and'res mache! Code-Behind mit 11 tausend Lines of Code - Das ist doch der Maintenance- Tod! Post-Back und Controls im Web, dass kannst'e doch nich' testen, Depp!
  8. 8. Concepts • Nice URLs & Routing • Process over „just add a Form“ • Loads of naming conventions • Code, Code, Code • As strongly typed as possible! • Once build, forever used…
  9. 9. Nice URLs • Vs
  10. 10. Process
  11. 11. The MVC Pattern • The request hits the controller • Loads the model • Returns the view to return to the client Controller Model View
  12. 12. Strongly Typed <%= DisplayFor(m=>m.Title) %> Instead of <%# Eval("Title") %>
  13. 13. Concepts cont. • No Code-Behind for ASPXs • No Postbacks • No Viewstate • No controls out of Redmond!
  14. 14. IIS sends Response ViewResult.Render ViewResult locates corresponding View ActionResult. ExecuteResult ActionResult builds ViewData / Model Controller.{Action}Controller.ExecuteIControllerFactory IHttpHandler. ProcessRequest MvcRouteHandler (IHttpHandler) IRouteHandler. GetHttpHandler URLRoutingModule IIS takes Request
  15. 15. Defining Routes routes.Ignore("*.svc"); routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = "" });
  16. 16. Actions public ActionResult Index() { return View(); }
  17. 17. Passing Data public ActionResult Index() { ViewData["Message"] = "Welcome to ASP.NET MVC!"; return View(); }
  18. 18. Passing Typed Data public ActionResult Index() { var p = new Person(); return View(p); }
  19. 19. Model Binder public ActionResult Save(Person p) { // No need to cope with Form/QueryString return View(); }
  20. 20. ASPX Views Untyped <%@ Page Inherits="ViewPage<dynamic>" %> Typed <%@ Page Inherits="ViewPage<Product>" %>
  21. 21. Event-driven RESTful ASP.NET RoR, MonoRail, ASP.NET MVC Stateful Stateless Heavyweight Lightweight Overcomes HTTP Embraces HTTP Widgets HTML 3rd-party controls DIY Design view Code view GUI Web page Postbacks POSTs Web 1.0 (uncool) Web 2.0 (cool)
  22. 22. WHAT IS REST?
  23. 23. What is REST? • A term coined by Roy Fielding • Style of architecture • Resource based • Cacheable • NOT SOAP, NOR SESSION • Web Standards!
  24. 24. What is REST • Every Resource has a unique URI – But it's NOT about CRUD! • Relies on HTTP verbs • Deliver Content as Requested
  25. 25. Action Attributes • HttpPost, HttpGet, HttpDelete, RequiresHttps • Authorize • ...
  26. 26. Action Filters public class MyFilter : ActionFilterAttribute { public override void OnActionExecuting( ActionExecutingContext filterContext) { // Your code here… } }
  27. 27. Action Results public class ModelResult<T> : ActionResult { public override void ExecuteResult( ControllerContext context) { var r = context.HttpContext.Response; r.Write(…); } }
  28. 28. Summary • ASP.NET MVC offers an alternative to WCF WebHTTP features – It's more Web • Fully integrated into a web application – It's less Services • No other protocols • No WSDL • No Proxies

×