2011 - dnc: rest wars
TRANSCRIPT
![Page 1: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/1.jpg)
REST Warsdaniel.fisher@devcoach
.com
![Page 2: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/2.jpg)
devcoach.comBERTAUNG + SCHULUNG + PROJEKTE
• Themen– Architektur & Technologie
Evaluierung, Performance Optimierung, Entwicklungs-Unterstützung, Security Reviews, QA, POC & Know-how-Transfer
• Technologien– Services: WCF & WF– Data: ADO.NET & EF– Web: ASP.NET, MVC & Silverlight
• Kunden– Versicherung, Finanzindustrie,
Mittelstand, Handel, Kommunikation, Softwarehersteller… Und sie?
• Kontakt– [email protected]
![Page 3: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/3.jpg)
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– Community Leader & Insider (CLIP)– Certified Professional Developer– Business Platform Technology Advisor
• lennybacon.com– Blog
• twitter.com– @lennybacon
![Page 4: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/4.jpg)
Efficient Communication…
![Page 5: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/5.jpg)
Agenda
• Introducing REST• WCF WebHttp• ASP.NET MVC• WCF Web API• Summary
![Page 6: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/6.jpg)
Introducing REST
![Page 7: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/7.jpg)
Introducing REST
![Page 8: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/8.jpg)
![Page 9: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/9.jpg)
![Page 10: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/10.jpg)
![Page 11: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/11.jpg)
![Page 12: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/12.jpg)
![Page 13: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/13.jpg)
![Page 14: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/14.jpg)
![Page 15: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/15.jpg)
![Page 16: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/16.jpg)
![Page 17: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/17.jpg)
![Page 18: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/18.jpg)
Windows Communication Foundation WebHttp
![Page 19: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/19.jpg)
Unified Programming Model
Interopwith otherplatforms
ASMX
Attribute- Based
Programming
Enterprise Services
WS-*ProtocolSupport
WSE
Message-Oriented
Programming
System.Messaging
ExtensibilityLocation
transparency
.NET Remoting
![Page 20: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/20.jpg)
WS-*
Security
Messaging
ReliableMessaging Transactions
Meta
data
XML
![Page 21: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/21.jpg)
The Microsoft Web PlatformM
icro
soft
Web
Pla
tform
Vis
ual Stu
dioASP.NET Web
Forms
ADO.NET
SQL Server
Internet Information Services
ASP.NET MVC
Silverlight MsAjax jQuery
WCF
![Page 22: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/22.jpg)
Address, Binding & Contract
Caller Service
MessageABC A B C
A B C
Address Binding Contract
(Where) (How) (What)
![Page 23: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/23.jpg)
Address
public class Global : HttpApplication{ void Application_Start( object sender, EventArgs e) { RouteTable.Routes.Add( new ServiceRoute( string.Empty, new WebServiceHostFactory(), typeof(SessionPlanerService))); }}
![Page 24: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/24.jpg)
Binding
<bindings> <basicHttpBinding> <binding configurationName="Binding1" hostNameComparisonMode="StrongWildcard" sendTimeout="00:10:00" maxMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" </binding> </basicHttpBinding></bindings>
![Page 25: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/25.jpg)
Contract + Address (parts)
[ServiceContract]public interface ISessionPlaner{ [WebGet(UriTemplate = "Sessions")] List<SessionDetail> GetAllSessions();}
![Page 26: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/26.jpg)
demo!
![Page 27: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/27.jpg)
Automatic Format Selection
<system.serviceModel> <standardEndpoints> <webHttpEndpoint> <standardEndpoint name="" automaticFormatSelectionEnabled="true"> <security mode="None"/>
![Page 28: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/28.jpg)
Extensibilitypublic class MyBehavior : WebHttpBehavior{}
public class MyClientFormatter : IClientMessageFormatter{}
public class MyDispatchFormatter : IDispatchMessageFormatter{}
public class MyEndpointBehavior : BehaviorExtensionElement , IEndpointBehavior{}
![Page 29: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/29.jpg)
Extensibility<system.serviceModel> <behaviors> <endpointBehaviors> <behavior name="SomeName"> <myExtension /> </behavior> </endpointBehaviors> </behaviors> <services> <service name="Service"> <endpoint address="" binding="basicHttpBinding" contract="IService" behaviorConfiguration="SomeName"/> </service> </services> <extensions> <behaviorExtensions> <add name="myExtension" type="devcoach.ServiceModel.SomeEndpointBehavior, devcoach.ServiceModel, …"/> </behaviorExtensions> </extensions></system.serviceModel>
![Page 30: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/30.jpg)
Extensibility Client<system.serviceModel> <behaviors> <endpointBehaviors> <behavior name="SomeName"> <myExtension /> </behavior> </endpointBehaviors> </behaviors> <client> <endpoint name="SomeEntpointName" address="" binding="basicHttpBinding" contract="IService" behaviorConfiguration="SomeName"/> </client> <extensions> <behaviorExtensions> <add name="myExtension" type="devcoach.ServiceModel.SomeEndpointBehavior, devcoach.ServiceModel, …"/> </behaviorExtensions> </extensions></system.serviceModel>
![Page 31: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/31.jpg)
demo!
![Page 32: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/32.jpg)
ASP.NET MVC
![Page 33: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/33.jpg)
The Microsoft Web PlatformM
icro
soft
Web
Pla
tform
Vis
ual Stu
dioASP.NET Web
Forms
ADO.NET
SQL Server
Internet Information Services
ASP.NET MVC
Silverlight MsAjax jQuery
WCF
![Page 34: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/34.jpg)
ASP.NET ArchitectureA
pplic
ati
on
Pool
ASP.
NE
T (
Htt
pR
unti
me)
HttpApplication Application_Start
Application_End
Application_Error
…
HttpContext
RequestModules
HttpHandler
Begin_Request
ResponseModules
Authenticate_Request
…
UpdateRequestCache
PostRequestHandlerExecuted
…
Kern
el C
ach
e
![Page 35: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/35.jpg)
− The request hits the Controller.− The Model is loaded.− The View is provided with data and − renders markup to the
client.
Controller
Model
View
1
2
3
4
![Page 36: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/36.jpg)
Uripublic static void RegisterRoutes(RouteCollection routes){ routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", // if parameter not in URL action = "Index", // if parameter not in URL id = UrlParameter.Optional } // Parameter defaults );}
![Page 37: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/37.jpg)
Functionality
using System.Web.Mvc;
…
public class HomeController : Controller
{ [HttpGet]
public ActionResult About()
{
return WhateverResult();
}
}
![Page 38: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/38.jpg)
demo!
![Page 39: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/39.jpg)
Extensibilitypublic class MyFilterAttribute
: ActionFilterAttribute
{
public override void OnActionExecuting(
ActionExecutingContext filterContext)
{
// Before...
}
public override void OnActionExecuted(
ActionExecutedContext filterContext)
{
// After...
}
}
![Page 40: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/40.jpg)
Extensibilitypublic class ModelResult<T> : ActionResult { public override void ExecuteResult( ControllerContext context) { var r = context.HttpContext.Response; r.Write(…); }}
![Page 41: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/41.jpg)
demo!
![Page 42: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/42.jpg)
Windows Communication Foundation WCF Web API
![Page 43: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/43.jpg)
New Message Types
• HttpResponseMessage, JsonValue
![Page 44: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/44.jpg)
demo!
![Page 45: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/45.jpg)
Extensibility
public class MyFormatter : MediaTypeFormatter{}public class MyChannel : DelegatingChannel{}
![Page 46: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/46.jpg)
Extensibilityprotected void Application_Start(object sender, EventArgs e){ var config = HttpHostConfiguration.Create(). AddFormatters(new MyFormatter()). AddMessageHandlers(typeof(MyChannel)); SetMappings();
RouteTable.Routes.MapServiceRoute<MyService>("Contact", config);}
public void SetMappings(){ var mappings = new List<UriExtensionMapping>(); mappings.AddMapping("xml", "application/xml"); SetUriExtensionMappings(mappings);}
![Page 47: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/47.jpg)
demo!
![Page 48: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/48.jpg)
Summary
• WCF 4.0 WebHTTP– Released with the .NET Framework.– Easy to start with REST, if you already
have WCF in the house.– Advanced goals can be reached,but with
high effort.– Distance to the Web can be felt.
![Page 49: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/49.jpg)
Summary
• ASP.NET MVC– Version 3.0 released as separate
Product.– Easy to start with REST, if you know any
Web-Platform.– Advanced goals can be easily reached
with small effort.– It's the raw Web.
![Page 50: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/50.jpg)
Summary
• WCF 4.0 WebAPIHTTP– Currently a Preview Release.– Easy to adopt from the WCF perspective.– Advanced goals can be reached, with
less high effort.– Still Abstracted from the web.
![Page 51: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/51.jpg)
Resources
• WCF 4.0 WebHTTP– Part of the Platform
• http://www.microsoft.com/downloads/en/details.aspx?FamilyID=0a391abd-25c1-4fc0-919f-b21f31ab88b7
– Hotfix for jQuery• http://wcf.codeplex.com/
• ASP.NET MVC 3.0– Released Product
• http://www.asp.net/mvc
• WCF Web API– CTP 4
• http://wcf.codeplex.com/releases/view/64449
![Page 52: 2011 - DNC: REST Wars](https://reader034.vdocuments.pub/reader034/viewer/2022042608/55bab137bb61eb79058b4574/html5/thumbnails/52.jpg)
Q&A