RESTful WCF Services


Published on

Published in: Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

RESTful WCF Services

  1. 1. ASP.NET – WCF & REST<br />Harish Ranganathan<br />Web Developer Evangelist<br />Microsoft Corporation India<br />
  2. 2. Source:<br />
  3. 3. 1993:<br />Web == Content<br />
  4. 4. The Browser<br />Generic client experience <br />URI’s<br />Addressing and identification <br />HTML<br />Common presentation format<br />Hyperlinks<br />Anarchic interconnectivity <br />HTTP GET<br />Common operation everything supports<br />Content-Driven Web Architecture<br />
  5. 5. 2008:<br />Web == Content + Capabilities<br />
  6. 6. Capability-Enabled Web Architecture<br />Rich Browser Clients<br />Programmability via script or plugins<br />HTTP<br />Baseline application protocol<br />Common set of operations + status codes<br />Domain-neutral data-oriented formats<br />JSON, Atom/Atom Publishing<br />Refine to support domain-specific schemas<br />Presentation formats<br />HTML, CSS<br />
  7. 7. RESTful Tenents<br />The Web is a graph of linked Resources<br />Resources are identified by URI’s<br />Resources support a fixed set of operations<br />In practice, these are defined by HTTP<br />Applications follow links to achieve late binding<br />REST is an architectural style, not a specification<br />
  8. 8. REST Continuum<br />RESTfullness<br />Purists<br />Pragmatists<br />Well Constructed URIs<br />HTTP Verbs<br />GET – Fetch<br />PUT – Update/Insert<br />DELETE – Delete<br />POST – Append<br />Standard Representations<br /><ul><li>POST to 1 URI OKQuerystrings OK
  9. 9. HTTP Verbs
  10. 10. GET – Fetch
  11. 11. POST – Overloaded
  12. 12. AJAX Services
  13. 13. POX OK</li></li></ul><li>webHttpBinding<br />New “web-friendly” WCF Binding in Fx 3.5<br />Allows for the development of RESTful services<br />Does not use SOAP envelopes<br />HTTP and HTTPS Transports Only<br />Supports several wire formats:<br />XML<br />JSON<br />Binary (streams)<br />
  14. 14. WebServiceHost<br />Specialized SerivceHost for RESTful services<br />Eliminates need for lots of configuration<br />Automatically configures address, binding, contract<br />Optimized for single-endpoint services<br />Use from .svc file:<br />&lt;%@ ServiceHost Language=&quot;C#&quot; Debug=&quot;true&quot; <br /> Service=&quot;Caching1.FeedService&quot; Factory=“System.ServiceModel.Activation.WebServiceHostFactory” %&gt;&quot;%&gt;<br />
  15. 15. [WebGet] And [WebInvoke]<br />Binds a WCF operation to URI space and HTTP method<br />Indicate the HTTP Method for the operation<br />WebGet – Don’t make me write it<br />WebInvoke – All verbs other than GET (Method parameter takes in the name of the Verb)<br />Other Parameters<br />BodyStyle – Indicates whether the Request/ Response are wrapped or not<br />RequestFormat – Json or Xml<br />ResponseFormat – Json or Xml<br />UriTemplate – Rich binding to URI<br />
  16. 16. UriTemplate<br />String that allows you to define the structure of the URI, as well as to define “Holes” <br />The “Holes” are variables<br />You Bind the template with parameters to fill the holes<br />{productId} hole / variable gets bound to productId parameter in operation<br />Variable<br />[OperationContract]<br />[WebGet(UriTemplate=“product/{productId}&quot;)]<br />ProductGetProduct(intproductId);<br />
  17. 17. WCF REST Starter Kit<br />Microsoft.ServiceModel.Web.dll<br />New features supporting RESTful services<br />Visual Studio 2008 Templates<br />REST Collections/Singleton Services<br />Atom Feed/Atom Publishing Protocol<br />HTTP/POX Services<br />REST Samples<br />Codeplex Project<br />Released at PDC<br />Written by WCF team<br />Features may be included in .NET 4.0<br />
  18. 18. What We&apos;ve Talked About Today<br />REST and the “zen” of the web<br />WCF features for REST scenarios<br />[WebGet] + [WebInvoke]<br />UriTemplate<br />WebHttpBinding<br />And many more…<br />The WCF REST Starter Kit<br />Available today at<br />
  19. 19. WebGet/WebInvoke Examples<br />[OperationContract]<br />[WebInvoke( Method=“PUT&quot;,<br />ResponseFormat=WebMessageFormat.Json,<br />UriTemplate=“product/{productId}&quot;)]<br />ProductUpdateProduct(intproductId, product p);<br />[OperationContract]<br />[WebGet( ResponseFormat=WebMessageFormat.Json,<br />UriTemplate=“product/{productId}&quot;)]<br />ProductDataGetProduct(intproductId);<br />
  20. 20.<br />questions<br />
  21. 21. © 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.<br />The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.<br />