KEMBAR78
Wcf rest api introduction | PPTX
Doing REST with new WCF Web API Himanshu DesaiSenior Consultant - ReadifyDiscover. Master. Influence.
AgendaWeb as Resource Oriented ArchitectureCurrent Industry TrendsOverview of RESTWhat is REST? REST ConstraintsREST BenefitsREST using WCFREST Support in WCFWCF Web API Discover. Master. Influence.
Resource Oriented Architecture3Discover. Master. Influence.
Current Industry TrendsA Move to cloud-based computingA Migration away from SOAPMore browser based AppsAdoption of RESTOther standards like OAuth, WebSocketsDiscover. Master. Influence.4
What is REST? Representational State TransferIdea floated by Roy FieldingArchitecture Style (not a protocol or spec and it is not restricted to HTTP)Discover. Master. Influence.5
REST ConstraintsClient - serverStatelessCacheableLayeredUniform interfaceDiscover. Master. Influence.6
REST ConstraintsUniform interfaceClient - serverStatelessCacheableLayeredDiscover. Master. Influence.7
REST BenefitsScalability of component interactionsEvolvabilityReachIntermediary components to reduce latency, enforce security and encapsulate legacy systemsDiscover. Master. Influence.8
RESTful Services-1A Traditional RPC based ServiceMoving from Verb to NounUsersBookmarksDiscover. Master. Influence.9
RESTful Services-2Designing the Uri TemplateAn invidual user accountAn individual bookmarkA user’s collection of private/public bookmarkCollection of all public bookmarksApplying the Uniform HTTP InterfaceDiscover. Master. Influence.10
RESTful Services-211Discover. Master. Influence.
RESTful Services-3Designing Resource RepresentationDiscover. Master. Influence.12
RESTful Services-4Designing Resource Representation<User>	< Email>aaron@pluralsight.com</Email>	<Name>Aaron Skonnard</Name></User>Supporting Alternate Representation?tag={tag}&format=json{username}?tag={tag}&format=jsonusers/{username}?format=jsonusers/{username}/profile?format=jsonSecurity ConsiderationProviding Resource MetadataAvoiding RPC Tendencies13Discover. Master. Influence.
GET ExampleREQUESTGET /index.htmlHost: www.example.comRESPONSEHTTP/1.1 200 OKEtag: „3f80f-1b6-3e1cb03b”Content-Type: text/html; charset=UTF-8lDiscover. Master. Influence.14
POST ExamplePOST /order HTTP/1.1Host: amazon.netContent-Type: application/xmlContent-Length: 216<order xmlns="http://schemas.amazon.net/order"><drink>latte</drink></order>201 CreatedLocation: http://amazon.net/order/1234ContentType: application/xml<order xmlns="http://schemas.amazon.net/order">...lDiscover. Master. Influence.15
PUT ExamplePUT /payment/1234 HTTP/1.1Host: amazon.netContent-Type: application/xmlContent-Length: 216<payment xmlns="http://schemas.amazon.net/order"><cardNumber>...</cardNumber></order>200 OKContentType: application/vnd.amazon+xmlxmlns="http://schemas.amazon.net/order"><drink>Latte</drink><link href=„payment/1234” rel=„http://relations.amazon.net/payment”/></order>lDiscover. Master. Influence.16
Central PrincipleExistence of resource which is referenced with a global identifier (e.g. a image, document etc.)Communicate via a standard interface (e.g. HTTP)Exchange representations of these resources (HTML.XML,JSON etc.)Discover. Master. Influence.17
RESTful web servicesCollection of data Base URI e.g. http://ebay.com/items/1Internet Media type of the data supported by the web service. (JSON,XML etc.)Set of operation supported by the web service using HTTP methods (POST,GET,PUT or DELETE)Discover. Master. Influence.18
REST Using WCFDiscover. Master. Influence.
Rest Support ComparisonDiscover. Master. Influence.20
WCF Web APIHTTP is now a first class Content negotiationAutomatic help pagesService RoutesIntegration with ASP.NET CachingReach any client    (Browser, Devices, Silverlight, Desktop)Discover. Master. Influence.21
ResourceArchitectureOp Handler2Transport+EncoderMessage Handler 1 ResponseDiscover. Master. Influence.22DispatcherGetById?GetById?Op Handler 3Op Handler 4Op Handler 1Message Handler 2Request
ComponentsContent NegotiationCentral Configuration (Fluent API)Http  ClassesOperation Handler FactoryError HandlerMessage Handler Factory(Channel Level)Discover. Master. Influence.23
Classes for Request & ResponseHttpRequestMessage
HttpResponseMessage
HttpContent
HttpClientDiscover. Master. Influence.24
Content NegotiationSupport for Multiple Formats including an add-in modelif you want xml ,it gives xml and if you want Json, it gives JsonDiscover. Master. Influence.25
DemoContent NegotiationDiscover. Master. Influence.
Operation Handler FactoryResponsible for creating new instances of Media Type Formatters and Operation Handlers.Media Type Formatter Operation Handler - an abstract base class used to create transfer a set of input into a set of outputDiscover. Master. Influence.27
Operation Handler FactoryRequest PipelineResponse PipelineOperation HandlerOperation HandlerOperation HandlerOperation HandlerOperation HandlerOperation HandlerDispatchDiscover. Master. Influence.28
Message Handler FactoryOperationMessage Handler4Message Handler3Message Handler 1Message Handler2Discover. Master. Influence.29

Wcf rest api introduction

  • 1.
    Doing REST withnew WCF Web API Himanshu DesaiSenior Consultant - ReadifyDiscover. Master. Influence.
  • 2.
    AgendaWeb as ResourceOriented ArchitectureCurrent Industry TrendsOverview of RESTWhat is REST? REST ConstraintsREST BenefitsREST using WCFREST Support in WCFWCF Web API Discover. Master. Influence.
  • 3.
  • 4.
    Current Industry TrendsAMove to cloud-based computingA Migration away from SOAPMore browser based AppsAdoption of RESTOther standards like OAuth, WebSocketsDiscover. Master. Influence.4
  • 5.
    What is REST?Representational State TransferIdea floated by Roy FieldingArchitecture Style (not a protocol or spec and it is not restricted to HTTP)Discover. Master. Influence.5
  • 6.
    REST ConstraintsClient -serverStatelessCacheableLayeredUniform interfaceDiscover. Master. Influence.6
  • 7.
    REST ConstraintsUniform interfaceClient- serverStatelessCacheableLayeredDiscover. Master. Influence.7
  • 8.
    REST BenefitsScalability ofcomponent interactionsEvolvabilityReachIntermediary components to reduce latency, enforce security and encapsulate legacy systemsDiscover. Master. Influence.8
  • 9.
    RESTful Services-1A TraditionalRPC based ServiceMoving from Verb to NounUsersBookmarksDiscover. Master. Influence.9
  • 10.
    RESTful Services-2Designing theUri TemplateAn invidual user accountAn individual bookmarkA user’s collection of private/public bookmarkCollection of all public bookmarksApplying the Uniform HTTP InterfaceDiscover. Master. Influence.10
  • 11.
  • 12.
    RESTful Services-3Designing ResourceRepresentationDiscover. Master. Influence.12
  • 13.
    RESTful Services-4Designing ResourceRepresentation<User> < Email>aaron@pluralsight.com</Email> <Name>Aaron Skonnard</Name></User>Supporting Alternate Representation?tag={tag}&format=json{username}?tag={tag}&format=jsonusers/{username}?format=jsonusers/{username}/profile?format=jsonSecurity ConsiderationProviding Resource MetadataAvoiding RPC Tendencies13Discover. Master. Influence.
  • 14.
    GET ExampleREQUESTGET /index.htmlHost:www.example.comRESPONSEHTTP/1.1 200 OKEtag: „3f80f-1b6-3e1cb03b”Content-Type: text/html; charset=UTF-8lDiscover. Master. Influence.14
  • 15.
    POST ExamplePOST /orderHTTP/1.1Host: amazon.netContent-Type: application/xmlContent-Length: 216<order xmlns="http://schemas.amazon.net/order"><drink>latte</drink></order>201 CreatedLocation: http://amazon.net/order/1234ContentType: application/xml<order xmlns="http://schemas.amazon.net/order">...lDiscover. Master. Influence.15
  • 16.
    PUT ExamplePUT /payment/1234HTTP/1.1Host: amazon.netContent-Type: application/xmlContent-Length: 216<payment xmlns="http://schemas.amazon.net/order"><cardNumber>...</cardNumber></order>200 OKContentType: application/vnd.amazon+xmlxmlns="http://schemas.amazon.net/order"><drink>Latte</drink><link href=„payment/1234” rel=„http://relations.amazon.net/payment”/></order>lDiscover. Master. Influence.16
  • 17.
    Central PrincipleExistence ofresource which is referenced with a global identifier (e.g. a image, document etc.)Communicate via a standard interface (e.g. HTTP)Exchange representations of these resources (HTML.XML,JSON etc.)Discover. Master. Influence.17
  • 18.
    RESTful web servicesCollectionof data Base URI e.g. http://ebay.com/items/1Internet Media type of the data supported by the web service. (JSON,XML etc.)Set of operation supported by the web service using HTTP methods (POST,GET,PUT or DELETE)Discover. Master. Influence.18
  • 19.
    REST Using WCFDiscover.Master. Influence.
  • 20.
  • 21.
    WCF Web APIHTTPis now a first class Content negotiationAutomatic help pagesService RoutesIntegration with ASP.NET CachingReach any client (Browser, Devices, Silverlight, Desktop)Discover. Master. Influence.21
  • 22.
    ResourceArchitectureOp Handler2Transport+EncoderMessage Handler1 ResponseDiscover. Master. Influence.22DispatcherGetById?GetById?Op Handler 3Op Handler 4Op Handler 1Message Handler 2Request
  • 23.
    ComponentsContent NegotiationCentral Configuration(Fluent API)Http ClassesOperation Handler FactoryError HandlerMessage Handler Factory(Channel Level)Discover. Master. Influence.23
  • 24.
    Classes for Request& ResponseHttpRequestMessage
  • 25.
  • 26.
  • 27.
  • 28.
    Content NegotiationSupport forMultiple Formats including an add-in modelif you want xml ,it gives xml and if you want Json, it gives JsonDiscover. Master. Influence.25
  • 29.
  • 30.
    Operation Handler FactoryResponsiblefor creating new instances of Media Type Formatters and Operation Handlers.Media Type Formatter Operation Handler - an abstract base class used to create transfer a set of input into a set of outputDiscover. Master. Influence.27
  • 31.
    Operation Handler FactoryRequestPipelineResponse PipelineOperation HandlerOperation HandlerOperation HandlerOperation HandlerOperation HandlerOperation HandlerDispatchDiscover. Master. Influence.28
  • 32.
    Message Handler FactoryOperationMessageHandler4Message Handler3Message Handler 1Message Handler2Discover. Master. Influence.29
  • 33.
    Query CompositionSupport forOData like query supporthttp://localhost/AlbumService/albums?$Top=5http://localhost/AlbumService/albums?$Top=5&$OrderBy=TitleDiscover. Master. Influence.30
  • 34.
    Consuming RESTful ServicesConsumingwith JavascriptConsuming with WCF31Discover. Master. Influence.
  • 35.
    Consuming Web APIwith Javascript32Discover. Master. Influence.
  • 36.
    HttpClientHelps you accessweb resources using Linqvar client = new HttpClient(address); var personQuery = client.CreateQuery<Person>(); var results = personQuery.ExecuteAsync().ContinueWith(p => {//Dosomething here });Discover. Master. Influence.33
  • 37.
    DemoQuery Composition &HttpClientDiscover. Master. Influence.
  • 38.

Editor's Notes

  • #3 http://msdn.microsoft.com/en-us/library/dd203052.aspx
  • #6 Representational State TransferIdea floated by Roy FieldingArchitectural Style (not a protocol or spec and it is not restricted to HTTP)ConceptREST-style architectures consist of clients and servers. Clients initiate requests to servers; servers process requests and return appropriate responses. Requests and responses are built around the transfer of representations of resources. A resource can be essentially any coherent and meaningful concept that may be addressed. A representation of a resource is typically a document that captures the current or intended state of a resource.At any particular time, a client can either be in transition between application states or &quot;at rest&quot;. A client in a rest state is able to interact with its user, but creates no load and consumes no per-client storage on the servers or on the network.The client begins sending requests when it is ready to make the transition to a new state. While one or more requests are outstanding, the client is considered to be in transition. The representation of each application state contains links that may be used next time the client chooses to initiate a new state transition.REST was initially described in the context of HTTP, but is not limited to that protocol. RESTful architectures can be based on other Application Layer protocols if they already provide a rich and uniform vocabulary for applications based on the transfer of meaningful representational state. RESTful applications maximize the use of the pre-existing, well-defined interface and other built-in capabilities provided by the chosen network protocol, and minimize the addition of new application-specific features on top of it.
  • #9 Evolvability In a RESTful system the entire infrastructure- including intermediaries such as load-balancers, caches, proxies etc. becomes participants in the communication.
  • #10 Evolvability In a RESTful system the entire infrastructure- including intermediaries such as load-balancers, caches, proxies etc. becomes participants in the communication.
  • #11 Evolvability In a RESTful system the entire infrastructure- including intermediaries such as load-balancers, caches, proxies etc. becomes participants in the communication.
  • #13 Evolvability In a RESTful system the entire infrastructure- including intermediaries such as load-balancers, caches, proxies etc. becomes participants in the communication.
  • #21 In 3.5 &amp; 4.0New Attributes (WebGet/WebInvoke)New Binding (WebHttpBinding)Routing, help pages etc.Partial Support for Content negotiationIn .NET 4, Out of box XML and Json were supported. If you need to support other types , you need to extent webcontenttypemapper.Service routes- provides compile time checking. Integrates with ASP.NET RoutingYou host service which is then available as a route.WCF Web APIHTTP is now a first class Content negotiationAutomatic help pagesService RoutesIntegration with ASP.NET CachingReach any client (Browser, Devices, Silverlight, Desktop)
  • #22 Service routes- provides compile time checking. Integrates with ASP.NET RoutingYou host service which is then available as a route.