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

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

There is time for rest

1,122
views

Published on

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

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

Published in: Technology

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,122
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
17
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. There is time for REST
    WCF REST Services
  • 2. Overview
    What is REST
    Rules and Guidelines
    Hosting a REST Service in .NET
    Consuming a REST Service with .NET
    Samples
    Discussion
  • 3. What is REST?
    Roy Fieldinghttp://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm
  • REST Constraints
    Separation resource from representation
    Uniform interface
    Self-descriptive messages
    Hypermedia as engine of application state
  • 7. HTTP Methods
  • 8. HTTP Methods
  • 9. HTTP Status Codes
  • 10. 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 />
  • 11. 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
  • 12. 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
  • 13. Return Types
    XML
    XHTML
    ATOM Publishing Protocol
    RSS
    Custom (should contain hyperlinks)
    JSON
    Custom
  • 14. WCF and REST
    WCF 4 REST
    REST endpoints
    Uri templates for routing
    WCF Hosting (Console, IIS, etc) etc.
  • 15. 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
  • 16. WCF REST contract
    [ServiceContract]
    publicinterfaceIAutomobileService
    {
    [OperationContract]
    [WebGet(UriTemplate = "*")]
    Message Get();
    [OperationContract]
    [WebInvoke(Method = "PUT", UriTemplate = "*")]
    Message Put(Message data);
    }
  • 17. Uri Templates
    [ServiceContract]
    public interface IAutomobileService
    {
    [OperationContract]
    [WebGet(UriTemplate = "/{year}/{make}/{model}/{engine}")]
    AutomobilesGetAutomobiles(string year, string make,
    string model, string engine);
    }
  • 18. Routing
    staticvoidRegisterRoutes(RouteCollection routes)
    {
    routes.MapServiceRoute<SampleResource>("api");
    }
    voidApplication_Start(objectsender,EventArgs e)
    {
    RegisterRoutes(RouteTable.Routes);
    }
  • 19. Consuming REST .NET
  • 20. 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.
    }
  • 21. 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");
    }
  • 22. 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));
    }
  • 23. Tools
    Fiddlerhttp://www.fiddler2.com/fiddler2/
    Firebughttp://getfirebug.com
    IEWatchhttp://www.iewatch.com/
  • 24. Show me the code
  • 25. 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
  • 26. Books
  • 27. 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