There is time for rest
Upcoming SlideShare
Loading in...5
×
 

There is time for rest

on

  • 1,345 views

Презентація підготовлена та проводиться Романом Калитою (Львів)

Презентація підготовлена та проводиться Романом Калитою (Львів)

Statistics

Views

Total Views
1,345
Views on SlideShare
1,014
Embed Views
331

Actions

Likes
1
Downloads
15
Comments
0

4 Embeds 331

http://softserve.ua 325
http://ssua.devqub.com 3
http://m.softserve.ua 2
http://translate.googleusercontent.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

There is time for rest There is time for rest Presentation Transcript

  • There is time for REST
    WCF REST Services
  • Overview
    What is REST
    Rules and Guidelines
    Hosting a REST Service in .NET
    Consuming a REST Service with .NET
    Samples
    Discussion
  • What is REST?
    Roy Fieldinghttp://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm
    • Client-Server
    • Stateless
    • Cachable
    • Layered System
  • REST Constraints
    Separation resource from representation
    Uniform interface
    Self-descriptive messages
    Hypermedia as engine of application state
  • HTTP Methods
  • HTTP Methods
  • HTTP Status Codes
  • HTTP Messages
    Request
    GET http://localhost:1128/api?$skip=2&$top=2 HTTP/1.1
    User-Agent: Fiddler
    Host: localhost:1128
    Accept: application/xml
    Response
    HTTP/1.1 200 OK
    Cache-Control: private
    Content-Length: 157
    Content-Type: application/xml; charset=utf-8
    Server: Microsoft-IIS/7.5
    Date: Fri, 26 Aug 2011 18:51:22 GMT
    <?xml version="1.0" encoding="utf-8"?>
    <Data />
  • URIs
    RPC (SOAP) Interface
    http://example.com/CarsService/getYears
    http://example.com/CarsService/getMakes
    http://example.com/CarsService/getAutomobile
    http://example.com/CarsService/updateAutomobile
    http://example.com/CarsService/deleteAutomobile
  • URIs
    RESTful Interface
    No need to distinguish get/update/delete, that’s what the HTTP Method is for
    Collection
    http://example.com/2011/Honda/
    Resource
    http://example.com/2011/Honda/Civic/2.0
  • Return Types
    XML
    XHTML
    ATOM Publishing Protocol
    RSS
    Custom (should contain hyperlinks)
    JSON
    Custom
  • WCF and REST
    WCF 4 REST
    REST endpoints
    Uri templates for routing
    WCF Hosting (Console, IIS, etc) etc.
  • WCF 4 REST, Web Api
    Programming model for HTTP in WCF
    Access HTTP from top to bottom
    REST endpoints
    Uri templates for routing
    WCF Hosting (Console, IIS, etc) etc.
    Http Client
    Plug in any format / media type
    Typeless JSON support
    IQueryablesupport
  • WCF REST contract
    [ServiceContract]
    publicinterfaceIAutomobileService
    {
    [OperationContract]
    [WebGet(UriTemplate = "*")]
    Message Get();
    [OperationContract]
    [WebInvoke(Method = "PUT", UriTemplate = "*")]
    Message Put(Message data);
    }
  • Uri Templates
    [ServiceContract]
    public interface IAutomobileService
    {
    [OperationContract]
    [WebGet(UriTemplate = "/{year}/{make}/{model}/{engine}")]
    AutomobilesGetAutomobiles(string year, string make,
    string model, string engine);
    }
  • Routing
    staticvoidRegisterRoutes(RouteCollection routes)
    {
    routes.MapServiceRoute<SampleResource>("api");
    }
    voidApplication_Start(objectsender,EventArgs e)
    {
    RegisterRoutes(RouteTable.Routes);
    }
  • Consuming REST .NET
  • WebRequest
    varhttpRequest = (HttpWebRequest)WebRequest.Create(
    "http://localhost/myservice");
     
    using (varupStream = httpRequest.GetRequestStream())
    {
    // some complicated logic to create the message
    }
     
    var response = httpRequest.GetResponse();
    using (vardownStream = response.GetResponseStream())
    {
    // some complicated logic to handle the response message.
    }
  • WebChannelFactory
    [ServiceContract]
    publicinterfaceITwitterService
    {
    [OperationContract]
    [WebInvoke(UriTemplate = "/friendships/create/{user}.xml")]
    TwitterUserCreateFriendship(string user);
    }
     
    using (var factory = newWebChannelFactory<ITwitterService>(
    newUri("http://www.twitter.com/")))
    {
    factory.Credentials.UserName.UserName = username;
    factory.Credentials.UserName.Password = password;
    var proxy = factory.CreateChannel();
    var user = proxy.CreateFriendship("userToFollow");
    }
  • HttpClient
    var sample = newSample();
    using (var client = newHttpClient())
    {
    client.DefaultRequestHeaders.Accept.Add(
    newMediaTypeWithQualityHeaderValue("application/json"));
    client.Post(
    "http://localhost/myservice",
    newObjectContent(typeof(Sample),
    sample,
    Sample.JsonMediaType));
    }
  • Tools
    Fiddlerhttp://www.fiddler2.com/fiddler2/
    Firebughttp://getfirebug.com
    IEWatchhttp://www.iewatch.com/
  • Show me the code
  • Implementations
    OpenRastaOpenRasta brings the concept of REST to the .NET platform in ways that allow it to be deployed alongside ASP.NET and WCF components. http://trac.caffeine-it.com/openrasta/wiki/Doc
    http://code.google.com/p/implementing-rest/wiki/ByLanguage
  • Books
  • Resources
    WCF Web API
    • http://wcf.codeplex.com
    WCF Web APis: "There's a URI for That"
    • http://channel9.msdn.com/Events/MIX/MIX11/FRM14
    RFC HTTP
    • http://www.ietf.org/rfc/rfc2616.txt
    Implementing REST, small reference and list of frameworks
    • http://code.google.com/p/implementing-rest/
    REST on Wikipedia
    • http://en.wikipedia.org/wiki/REST