17

Click here to load reader

RESTful WCF Services

Embed Size (px)

Citation preview

Page 1: RESTful WCF Services

ASP.NET – WCF & REST

Harish RanganathanWeb Developer EvangelistMicrosoft Corporation India

Page 3: RESTful WCF Services

1993:Web == Content

Page 4: RESTful WCF Services

The BrowserGeneric client experience

URI’sAddressing and identification

HTMLCommon presentation format

HyperlinksAnarchic interconnectivity

HTTP GETCommon operation everything supports

Content-Driven Web Architecture

Page 5: RESTful WCF Services

2008:Web == Content + Capabilities

Page 6: RESTful WCF Services

Capability-Enabled Web Architecture

Rich Browser ClientsProgrammability via script or plugins

HTTPBaseline application protocolCommon set of operations + status codes

Domain-neutral data-oriented formatsJSON, Atom/Atom PublishingRefine to support domain-specific schemas

Presentation formatsHTML, CSS

Page 7: RESTful WCF Services

RESTful Tenents

The Web is a graph of linked ResourcesResources are identified by URI’sResources support a fixed set of operations

In practice, these are defined by HTTP

Applications follow links to achieve late binding

REST is an architectural style, not a specification

Page 8: RESTful WCF Services

REST Continuum

Well Constructed URIs

HTTP VerbsGET – FetchPUT – Update/InsertDELETE – DeletePOST – Append

Standard Representations

RESTfullness

POST to 1 URI OKQuerystrings OK

HTTP Verbs GET – Fetch POST –

Overloaded

AJAX Services POX OK

Purists Pragmatists

Page 9: RESTful WCF Services

webHttpBinding

New “web-friendly” WCF Binding in Fx 3.5

Allows for the development of RESTful servicesDoes not use SOAP envelopesHTTP and HTTPS Transports Only

Supports several wire formats:XMLJSONBinary (streams)

Page 10: RESTful WCF Services

WebServiceHost

Specialized SerivceHost for RESTful services

Eliminates need for lots of configurationAutomatically configures address, binding, contract

Optimized for single-endpoint servicesUse from .svc file:<%@ ServiceHost Language="C#" Debug="true"

Service="Caching1.FeedService" Factory=“System.ServiceModel.Activation.WebServiceHostFactory” %>"%>

Page 11: RESTful WCF Services

[WebGet] And [WebInvoke]

Binds a WCF operation to URI space and HTTP methodIndicate the HTTP Method for the operation

WebGet – 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 – Rich binding to URI

Page 12: RESTful WCF Services

UriTemplate

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);

Variable

Page 13: RESTful WCF Services

WCF REST Starter Kit

Microsoft.ServiceModel.Web.dllNew features supporting RESTful services

Visual Studio 2008 TemplatesREST Collections/Singleton ServicesAtom Feed/Atom Publishing ProtocolHTTP/POX Services

REST SamplesCodeplex Project

Released at PDCWritten by WCF teamFeatures may be included in .NET 4.0

Page 14: RESTful WCF Services

What We've Talked About Today

REST and the “zen” of the webWCF features for REST scenarios

[WebGet] + [WebInvoke]UriTemplateWebHttpBindingAnd many more…

The WCF REST Starter KitAvailable today at http://msdn.com/wcf/rest

Page 15: RESTful WCF Services

WebGet/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 16: RESTful WCF Services

http://geekswithblogs.net/ranganh

questions

Page 17: RESTful WCF Services

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