REST and WCF 3 5 Glen Gordon Developer

  • Slides: 24
Download presentation
REST and WCF 3. 5 Glen Gordon Developer Evangelist, Microsoft http: //blogs. msdn. com/glengordon

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

Session Objectives Provide you with an overview of REST Illustrate the new web. Http.

Session Objectives Provide you with an overview of REST Illustrate the new web. Http. Binding Show you how to create and consume REST services

Agenda Life before REST Understanding the Web SOAP Services WCF 3. 0 REST Overview

Agenda Life before REST Understanding the Web SOAP Services WCF 3. 0 REST Overview (including the REST Continuum) web. Http. Binding Overview Pragmatic REST Demo Purist REST Demo

The Web in the real world Everything (mostly) is URI addressable HTTP Verbs GET

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

SOAP Services (from 50, 000 feet) Typically overload POST Message body contains method information

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 POST /Product. Services. svc Host: www. somesite. com Sample: SOAPAction: Get. Product … <soap: Envelope xmlns: … <soap: Body> <Get. Product xmlns: … <Product. Id>1</Product. Id> </Get. Product> </soap: Body> </soap: Envelope>

WCF 3. 0 HTTP Bindings basic. Http. Binding SOAP Binding Conforms to WS-I Basic

WCF 3. 0 HTTP Bindings basic. Http. Binding SOAP Binding Conforms to WS-I Basic Profile 1. 0 standards ws. Http. Binding SOAP Binding Provides extended functionality ws-Atomic. Transaction ws-Reliable. Messaging etc. No “web-friendly” bindings

Agenda Life before REST Understanding the Web SOAP Services WCF 3. 0 REST Overview

Agenda Life before REST Understanding the Web SOAP Services WCF 3. 0 REST Overview (including the REST Continuum) web. Http. Binding Overview pragmatic REST Demo purist REST Demo

REST Representational State Transfer (REST) is a style of software architecture for distributed hypermedia

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. org

Foundations of REST Everything* can be modeled as a resource Every resource can have

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

Anatomy of an HTTP request Headers Verb URI GET /Control. Panel/Blogs/postlist. aspx HTTP/1. 1

Anatomy of an HTTP request Headers Verb URI GET /Control. Panel/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; SLCC 1; . NET CLR 2. 0. 50727; . NET CLR 1. 1. 4322; Tablet PC 2. 0; Info. Path. 2; . NET CLR 3. 5. 21022; . NET CLR 3. 0. 04506; MS-RTC LM 8) Host: blogs. msdn. com Proxy-Connection: Keep-Alive [optional] body

Anatomy of an HTTP response Headers Response code HTTP/1. 1 200 OK Proxy-Connection: Keep-Alive

Anatomy of an HTTP response Headers Response code HTTP/1. 1 200 OK Proxy-Connection: Keep-Alive Content-Type header 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 Connection: <!DOCTYPE html PUBLIC "-//W 3 C//DTD XHTML 1. 0 Frameset//EN" "http: //www. w 3. org/TR/xhtml 1/DTD/xhtml 1 -frameset. dtd"> <html xmlns="http: //www. w 3. org/1999/xhtml" xml: lang="en"> <head> <title>Community Server Control Panel </title…

Resources Anything Static objects (html files, images, etc) Entities that have a representation Results

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

URIs

URIs

URIs URL is an artifact of the readonly web http: //localhost/My. Application/images/img. jpg C:

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

Hi Lo - -R RE ST ES T REST Continuum Purists RESTfullness Well Constructed

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

Agenda Life before REST Understanding the Web SOAP Services WCF 3. 0 REST Overview

Agenda Life before REST Understanding the Web SOAP Services WCF 3. 0 REST Overview (including the REST Continuum) web. Http. Binding Overview pragmatic REST Demo purist REST Demo

web. Http. Binding New “web-friendly” WCF Binding in Fx 3. 5 Allows for the

web. Http. Binding 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 Web. Message. Encoding JSON XML Binary

[Web. Get] and [Web. Invoke] Indicate the HTTP Method for the operation Web. Get

[Web. Get] and [Web. Invoke] Indicate the HTTP Method for the operation Web. Get – Don’t make me write it Web. Invoke – All verbs other than GET (Method parameter takes in the name of the Verb) Other Parameters Body. Style – Indicates whether the Request / Response are wrapped or not Request. Format – Json or Xml Response. Format – Json or Xml Uri. Template – Covered in a minute…

Uri. Template String that allows you to define the structure of the URI, as

Uri. Template 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 Hole [Operation. Contract] [Web. Get(Uri. Template=“product/{product. Id}")] Product Get. Product(int product. Id); {product. Id} hole / variable gets bound to product. Id parameter in operation

web. Http. Binding Endpoint Behaviors - extend run-time behavior for an endpoint web. Http

web. Http. Binding Endpoint Behaviors - extend run-time behavior for an endpoint web. Http - enables the Web programming model for a WCF service enable. Web. Script – ASP. NET AJAX friendly endpoint behavior Aligns nicely with ASP. NET AJAX client Sub. Classes web. Http Provides ASP. NET AJAX proxy generation Only supports GET and overloaded POST Does not support Uri. Templates

DEMO Pragmatic (ASP. NET AJAX-Friendly) REST Services enable. Web. Script endpoint behavior Consuming with

DEMO Pragmatic (ASP. NET AJAX-Friendly) REST Services enable. Web. Script endpoint behavior Consuming with an ASP. NET AJAX Client Purist REST Services web. Http endpoint behavior Consuming with an AJAX Client

Summary REST principles borrow from principles of the web Architectures vary with regard to

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

Resources Steve Maine's Blog http: //hyperthink. net/blog/ Justin Smith's Blog http: //blogs. msdn. com/justinjsmith

Resources Steve Maine's Blog http: //hyperthink. net/blog/ Justin Smith's Blog http: //blogs. msdn. com/justinjsmith HTTP Programming with WCF and the. NET Framework 3. 5 http: //msdn. microsoft. commsdnmagissues 81WCFin. Orcas

Glen Gordon Developer Evangelist, Microsoft http: //blogs. msdn. com/glengordon © 2008 Microsoft Corporation. All

Glen Gordon Developer Evangelist, Microsoft http: //blogs. msdn. com/glengordon © 2008 Microsoft Corporation. All rights reserved. Microsoft, 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.