Presentation is loading. Please wait.

Presentation is loading. Please wait.

REST and WCF 3.5 Glen Gordon Developer Evangelist, Microsoft

Similar presentations


Presentation on theme: "REST and WCF 3.5 Glen Gordon Developer Evangelist, Microsoft"— Presentation transcript:

1 REST and WCF 3.5 Glen Gordon Developer Evangelist, Microsoft http://blogs.msdn.com/glengordon

2 Session Objectives Provide you with an overview of REST Illustrate the new webHttpBinding Show you how to create and consume REST services

3 Agenda Life before REST Understanding the Web SOAP Services WCF 3.0 REST Overview (including the REST Continuum) webHttpBinding Overview Pragmatic REST Demo Purist REST Demo

4 The Web in the real world Everything (mostly) is URI addressable HTTP Verbs GET - Most Prevalent POST – Overloaded, Used for actions PUT, DELETE – Largely Ignored Representation Format – (X)HTML HTTP Response Codes Stateless

5 SOAP Services (from 50,000 feet) Typically overload POST Message body contains method information Messages wrapped with a SOAP Envelope WSDL describes SOAP service WS-* provides extended functionality Standardized and interoperable Sample: POST /ProductServices.svc Host: www.somesite.com SOAPAction: GetProduct … <soap:Envelope xmlns: … <GetProduct xmlns: … 1

6 WCF Overview WCF Services are comprised of: Address – defines where the service is hosted Binding - specifies how the Endpoint communicates with the world Contract – defines the capabilities of the service

7 Sending a message with WCF Service Service Endpoints Dispatcher Client Proxy Channel Transport Channel Channel Transport Channel Binding

8 WCF 3.0 HTTP Bindings basicHttpBinding SOAP Binding Conforms to WS-I Basic Profile 1.0 standards wsHttpBinding SOAP Binding Provides extended functionality ws-AtomicTransactionws-ReliableMessagingetc. No “web-friendly” bindings

9 Agenda Life before REST Understanding the Web SOAP Services WCF 3.0 REST Overview (including the REST Continuum) webHttpBinding Overview pragmatic REST Demo purist REST Demo

10 REST Representational State Transfer (REST) is a style of software architecture for distributed hypermedia systems such as the World Wide Web From Wikipedia.org Representational State Transfer (REST) works on top of HTTP and takes advantage of URLs as a sort of "command line interface". In such an environment, one computer creates a URL defining a request from a second program or computer. Once received the second computer treats the URL as a command, processes it, and returns the results as an XML stream From osuosl.orgosuosl.org

11 REST Core Ideologies Simpler is better! The Web works and works well It works with the previously outlined features It has persevered due to its simplicity Some web services should follow the “way of the web”

12 REST Overview Resources are URI Addressable HTTP Headers important Content-type Response Code Standard representation formats (ATOM, XHTML?) Stateless Appropriate use of HTTP Verbs HTTP VerbActionSide effect GETFetch representationsSafe, Idempotent PUTUpdate, Insert NewIdempotent DELETEDeleteIdempotent POSTAppendNeither safe nor idempotent

13 Foundations of REST Everything* can be modeled as a resource Every resource can have one or more “names” Every resource can have one or more representations Resources are manipulated via the uniform interface Leverage HTTP features as recommended in the specs

14 Anatomy of an HTTP request GET /ControlPanel/Blogs/postlist.aspx HTTP/1.1 Accept: image/gif, … application/x-shockwave-flash, application/x-silverlight, */* Accept-Language : en-US,zh-CN;… Accept-Encoding: gzip, deflate User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1;.NET CLR 2.0.50727;.NET CLR 1.1.4322; Tablet PC 2.0; InfoPath.2;.NET CLR 3.5.21022;.NET CLR 3.0.04506; MS-RTC LM 8) Host: blogs.msdn.com Proxy-Connection: Keep-Alive Verb URI Headers [optional] body

15 HTTP/1.1 200 OK Proxy-Connection: Keep-Alive Connection : Keep-Alive Content-Length : 52535 Expires: -1 Date: Fri, 15 Feb 2008 00:52:40 GMT Content-Type: text/html; charset=utf-8 Server: Microsoft-IIS/6.0 … Cache-Control: no-cache Pragma: no-cache Anatomy of an HTTP response Response code Content-Type header Headers Community Server Control Panel Community Server Control Panel </title… Community Server Control Panel Community Server Control Panel </title…

16 Resources Anything Static objects (html files, images, etc) Entities that have a representation Results of queries & methods execution …

17 URIs

18 URIs URL is an artifact of the readonly web http://localhost/MyApplication/images/img.jpg C:\inetpub\wwwroot\MyApplication\images\img.jpg The Web does not distinguish between static & dynamic URI is a true identifier http://localhost/MyApplication/proc?id=256 http://localhost/MyApplication/proc/256 http://localhost/MyApplication/proc/lightsabre URIs partition the application space Transparent vs opaque

19 REST Continuum Well Constructed URIs HTTP Verbs GET – Fetch PUT – Update / Insert DELETE – Delete POST – Append Standard Representations RESTfullness Hi-REST Lo-REST POST to 1 URI OK Querystrings OK HTTP Verbs GET – Fetch POST - Overloaded POX OK Purists Pragmatists

20 Agenda Life before REST Understanding the Web SOAP Services WCF 3.0 REST Overview (including the REST Continuum) webHttpBinding Overview pragmatic REST Demo purist REST Demo

21 webHttpBinding New “web-friendly” WCF Binding in Fx 3.5 Allows for the development of RESTful services Works across REST Continuum HTTP and HTTPS Transports Only Does not use SOAP envelopes WebMessageEncodingJSONXMLBinary

22 [WebGet] and [WebInvoke] Indicate the HTTP Method for the operation WebGet – Don’t make me write it WebInvoke – All verbs other than GET (Method parameter takes in the name of the Verb) Other Parameters BodyStyle – Indicates whether the Request / Response are wrapped or not RequestFormat – Json or Xml ResponseFormat – Json or Xml UriTemplate – Covered in a minute…

23 UriTemplate String that allows you to define the structure of the URI, as well as to define “Holes” The “Holes” are variables You Bind the template with parameters to fill the holes {productId} hole / variable gets bound to productId parameter in operation [OperationContract] [WebGet(UriTemplate=“product/{productId}")] Product GetProduct(int productId); Hole

24 WebGet/WebInvoke Examples [OperationContract] [WebInvoke( Method=“DELETE", BodyStyle=WebMessageBodyStyle.Bare, RequestFormat=WebMessageFormat.Json, ResponseFormat=WebMessageFormat.Json, UriTemplate=“product/{productId}")] void DeleteProduct(int productId); [OperationContract] [WebGet( BodyStyle=WebMessageBodyStyle.Bare, RequestFormat=WebMessageFormat.Json, ResponseFormat=WebMessageFormat.Json, UriTemplate=“product/{productId}")] Product GetProduct(int productId);

25 webHttpBinding Endpoint Behaviors Endpoint Behaviors - extend run-time behavior for an endpoint webHttp - enables the Web programming model for a WCF service enableWebScript – ASP.NET AJAX friendly endpoint behavior Aligns nicely with ASP.NET AJAX client SubClasses webHttp Provides ASP.NET AJAX proxy generation Only supports GET and overloaded POST Does not support UriTemplates

26 DEMO Pragmatic (ASP.NET AJAX-Friendly) REST Services enableWebScript endpoint behavior Consuming with an ASP.NET AJAX Client Purist REST Services webHttp endpoint behavior Consuming with an AJAX Client

27 Summary REST principles borrow from principles of the web Architectures vary with regard to adherence to REST principles webHttpBinding supports architectures across the REST continuum enableWebScript Productivity features for ASP.NET AJAX applications Imposes limitations webHttp – Provides ability to implement services that adhere to strictest of standards

28 Resources Steve Maine's Blog - http://hyperthink.net/blog/ http://hyperthink.net/blog/ Justin Smith's Blog - http://blogs.msdn.com/justinjsmith http://blogs.msdn.com/justinjsmith HTTP Programming with WCF and the.NET Framework 3.5 http://msdn.microsoft.com\msdnmag\issues\0 8\01\WCFinOrcas http://msdn.microsoft.com\msdnmag\issues\0 8\01\WCFinOrcas http://msdn.microsoft.com\msdnmag\issues\0 8\01\WCFinOrcas

29 © 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. 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. Glen Gordon Developer Evangelist, Microsoft http://blogs.msdn.com/glengordon


Download ppt "REST and WCF 3.5 Glen Gordon Developer Evangelist, Microsoft"

Similar presentations


Ads by Google