Your SlideShare is downloading. ×
0
There is time for rest
There is time for rest
There is time for rest
There is time for rest
There is time for rest
There is time for rest
There is time for rest
There is time for rest
There is time for rest
There is time for rest
There is time for rest
There is time for rest
There is time for rest
There is time for rest
There is time for rest
There is time for rest
There is time for rest
There is time for rest
There is time for rest
There is time for rest
There is time for rest
There is time for rest
There is time for rest
There is time for rest
There is time for rest
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,148

Published on

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

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

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

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

×