22
Implementing RESTful Services With Windows Communication Foundation 3.5 SP1 Concepts and Introduction(Part 1 of 2)

Implementing RESTful Services With Windows Communication Foundation 3.5 SP1

Embed Size (px)

DESCRIPTION

Implementing RESTful Services With Windows Communication Foundation 3.5 SP1. Concepts and Introduction(Part 1 of 2). Session Objectives. Provide you with an overview of REST Understand the REST support of WCF 3.5 Learn how to build an AJAX-Friendly service - PowerPoint PPT Presentation

Citation preview

Page 1: Implementing RESTful Services With Windows Communication Foundation 3.5 SP1

Implementing RESTful Services With Windows Communication Foundation 3.5 SP1

Implementing RESTful Services With Windows Communication Foundation 3.5 SP1Concepts and Introduction(Part 1 of 2)

Page 2: Implementing RESTful Services With Windows Communication Foundation 3.5 SP1

Session ObjectivesSession Objectives

Provide you with an overview of RESTUnderstand the REST support of WCF 3.5Learn how to build an AJAX-Friendly service Learn how to build a HI-REST serviceGet you fired up with Demos

Page 3: Implementing RESTful Services With Windows Communication Foundation 3.5 SP1

AgendaAgenda

Why The Web WorksWhat is REST?How REST works in WCF 3.5LO-REST Demo (AJAX)HI-REST Demo (AJAX & Silverlight 2.0)

Page 4: Implementing RESTful Services With Windows Communication Foundation 3.5 SP1

Why The Web WorksWhy The Web Works

Simple & OpenAddressing scheme – URIApplication protocol – HTTPRepresentation Format - (X)HTMLResponse Codes – HTTP Status

Scales Best When StatelessCached

It works because people find value in it

Page 5: Implementing RESTful Services With Windows Communication Foundation 3.5 SP1

How do we move from a web of pages to a web of services?

How do we move from a web of pages to a web of services?Circa 1998

Page 6: Implementing RESTful Services With Windows Communication Foundation 3.5 SP1

SOAP Web ServicesSOAP Web Services

HTTP POST of an XML Message (SOAP Envelope)WSDL describes SOAP serviceWS-* provides extended functionalityStandardized and interoperable

<s:Envelope> <s:Header> <Action

s:mustUnderstand="1">http://t.org/IService1/GetData

</Action> </s:Header> <s:Body> <GetData> <value>1</value> </GetData> </s:Body></s:Envelope>

Page 7: Implementing RESTful Services With Windows Communication Foundation 3.5 SP1

WCF 3.0 SOAP/HTTP BindingsWCF 3.0 SOAP/HTTP Bindings

basicHttpBindingConforms to WS-I Basic Profile 1.1 standards Compatibile with ASP.NET Web Services (asmx)

wsHttpBindingA composable protocol stack allowing standards based additions

WS-Security

Page 8: Implementing RESTful Services With Windows Communication Foundation 3.5 SP1

AgendaAgenda

Why The Web WorksWhat is REST?How REST works in WCF 3.5LO-REST Demo (AJAX)HI-REST Demo (AJAX & Silverlight 2.0)

Page 9: Implementing RESTful Services With Windows Communication Foundation 3.5 SP1

RESTful TenentsRESTful Tenents

The Web of Services should work the way the Web of Pages works.Simple & OpenThe Universal API - HTTPLinked ResourcesServices Scale Best When

StatelessCached

Built into the HTTP protocol when leveraged properly

Page 10: Implementing RESTful Services With Windows Communication Foundation 3.5 SP1

REST ContinuumREST Continuum

Well Constructed URIsHTTP Verbs

GET – FetchPUT – Update / InsertDELETE – DeletePOST – Append

Standard Representations

RESTfullness

Hi-RES

T

Lo-R

EST

POST to 1 URI OKQuerystrings OKHTTP Verbs

GET – FetchPOST - Overloaded

AJAX Services

POX OK

Purists Pragmatists

Page 11: Implementing RESTful Services With Windows Communication Foundation 3.5 SP1

The Microsoft PositionThe Microsoft Position

SOAP is greatREST is greatUse WCF to build either one and go in peace

Page 12: Implementing RESTful Services With Windows Communication Foundation 3.5 SP1

AgendaAgenda

Why The Web WorksWhat is REST?How REST works in WCF 3.5LO-REST Demo (AJAX)HI-REST Demo (AJAX & Silverlight 2.0)

Page 13: Implementing RESTful Services With Windows Communication Foundation 3.5 SP1

webHttpBindingwebHttpBinding

New “web-friendly” WCF Binding in Fx 3.5Allows for the development of RESTful servicesDoes not use SOAP envelopesHTTP and HTTPS Transports Only

Works across REST ContinuumSupports all HTTP verbs

Web Message EncodingJSONXMLBinary (streams)

Page 14: Implementing RESTful Services With Windows Communication Foundation 3.5 SP1

[WebGet] and [WebInvoke][WebGet] and [WebInvoke]

Indicate the HTTP Method for the operationWebGet – Don’t make me write itWebInvoke – All verbs other than GET (Method parameter takes in the name of the Verb)

Other ParametersBodyStyle – Indicates whether the Request / Response are wrapped or notRequestFormat – Json or XmlResponseFormat – Json or XmlUriTemplate – Covered next …

Page 15: Implementing RESTful Services With Windows Communication Foundation 3.5 SP1

UriTemplateUriTemplate

String that allows you to define the structure of the URI, as well as to define “Holes”

The “Holes” are variablesYou 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

Page 16: Implementing RESTful Services With Windows Communication Foundation 3.5 SP1

WebGet/WebInvoke ExamplesWebGet/WebInvoke Examples

[OperationContract][WebInvoke( Method=“PUT", ResponseFormat=WebMessageFormat.Json, UriTemplate=“product/{productId}")]Product UpdateProduct(int productId, product p);

[OperationContract][WebGet( ResponseFormat=WebMessageFormat.Json, UriTemplate=“product/{productId}")]ProductData GetProduct(int productId);

Page 17: Implementing RESTful Services With Windows Communication Foundation 3.5 SP1

webHttpBinding Endpoint BehaviorswebHttpBinding Endpoint Behaviors

Endpoint Behaviors - extend run-time behavior for an endpointwebHttp - enables the Web programming model for a WCF serviceenableWebScript – ASP.NET AJAX friendly endpoint behavior

Aligns nicely with ASP.NET AJAX clientSubClasses webHttpProvides ASP.NET AJAX proxy generationOnly supports GET and overloaded POSTDoes not support UriTemplates

Page 18: Implementing RESTful Services With Windows Communication Foundation 3.5 SP1

DemoDemoLO-REST (AJAX Friendly)

Page 19: Implementing RESTful Services With Windows Communication Foundation 3.5 SP1

DemoDemoHI-REST

Page 20: Implementing RESTful Services With Windows Communication Foundation 3.5 SP1

SummarySummary

REST principles borrow from principles of the webArchitectures vary with regard to adherence to REST principleswebHttpBinding supports architectures across the REST continuum

enableWebScript Productivity features for ASP.NET AJAX applicationsImposes limitations

webHttp – Provides ability to implement services that adhere to strictest of standards

Page 22: Implementing RESTful Services With Windows Communication Foundation 3.5 SP1