Wcf building restful services
1 / 27

tl35: wcf: building restful services - PowerPoint PPT Presentation

  • Updated On :

WCF: Building RESTful Services.  Steve Maine Senior Program Manager Microsoft Corporation. Source : Pingdom.com. 1993: Web == Content. Content-Driven Web Architecture. The Browser Generic client experience URI’s Addressing and identification HTML Common presentation format

Related searches for tl35: wcf: building restful services

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'tl35: wcf: building restful services' - Samuel

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Wcf building restful services l.jpg

WCF: Building RESTful Services

 Steve Maine

Senior Program Manager

Microsoft Corporation

Slide2 l.jpg

Source: Pingdom.com

Slide3 l.jpg


Web == Content

Content driven web architecture l.jpg
Content-Driven Web Architecture

  • The Browser

    • Generic client experience

  • URI’s

    • Addressing and identification

  • HTML

    • Common presentation format

  • Hyperlinks

    • Anarchic interconnectivity


    • Common operation everything supports

Slide5 l.jpg


Web == Content + Capabilities

Capability enabled web architecture l.jpg
Capability-Enabled Web Architecture

  • Rich Browser Clients

    • Programmability via script or plugins

  • HTTP

    • Baseline application protocol

    • Common set of operations + status codes

  • Domain-neutral data-oriented formats

    • JSON, Atom/Atom Publishing

    • Refine to support domain-specific schemas

  • Presentation formats

    • HTML, CSS

Restful tenents l.jpg
RESTful Tenents

  • The Web is a graph of linked Resources

  • Resources are identified by URI’s

  • Resources 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

Rest continuum l.jpg
REST Continuum

  • Well Constructed URIs

  • HTTP Verbs

    • GET – Fetch

    • PUT – Update/Insert

    • DELETE – Delete

    • POST – Append

  • Standard Representations




  • POST to 1 URI OKQuerystrings OK

  • HTTP Verbs

    • GET – Fetch

    • POST – Overloaded

  • AJAX Services

  • POX OK

Ajax services with wcf l.jpg


AJAX Services with WCF

Webhttpbinding l.jpg

  • New “web-friendly” WCF Binding in Fx 3.5

    • Allows for the development of RESTful services

    • Does not use SOAP envelopes

    • HTTP and HTTPS Transports Only

  • Supports several wire formats:

    • XML

    • JSON

    • Binary (streams)

Webservicehost l.jpg

  • Specialized SerivceHost for RESTful services

    • Eliminates need for lots of configuration

    • Automatically configures address, binding, contract

  • Optimized for single-endpoint services

  • Use from .svc file:

<%@ ServiceHost Language="C#" Debug="true"

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

Webget and webinvoke l.jpg
[WebGet] And [WebInvoke]

  • Binds a WCF operation to URI space and HTTP method

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

Uritemplate l.jpg

  • 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





Wcf rest starter kit l.jpg


WCF REST Starter Kit

Wcf rest starter kit15 l.jpg
WCF REST Starter Kit

  • Microsoft.ServiceModel.Web.dll

    • New features supporting RESTful services

  • Visual Studio 2008 Templates

    • REST Collections/Singleton Services

    • Atom Feed/Atom Publishing Protocol

    • HTTP/POX Services

  • REST Samples

  • Codeplex Project

    • Released at PDC

    • Written by WCF team

    • Features may be included in .NET 4.0

The rest 0f wcf l.jpg



What we ve talked about today l.jpg
What We've Talked About Today

  • REST and the “zen” of the web

  • WCF features for REST scenarios

    • [WebGet] + [WebInvoke]

    • UriTemplate

    • WebHttpBinding

    • And many more…

  • The WCF REST Starter Kit

    • Available today at http://msdn.com/wcf/rest

Evals recordings l.jpg
Evals & Recordings

Please fill out your evaluation for this session at:

This session will be available as a recording at:


Please use the microphones provided l.jpg


Please use the microphones provided

Slide20 l.jpg

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

Webget webinvoke examples l.jpg
WebGet/WebInvoke Examples


[WebInvoke( Method=“PUT",



ProductUpdateProduct(intproductId, product p);


[WebGet( ResponseFormat=WebMessageFormat.Json,



Webprotocolexception l.jpg

  • CLR Exception that can be turned into HTTP status code on the wire

  • Can optionally carry detail information for display in the browser

[OperationContract, WebGet]

Stream EchoText(string text)


if( text == null )

throw new WebProtocolException( HttpStatusCode.BadRequest );

. . .


Adapterstream l.jpg

  • Used when you want a Stream or TextWriter but don’t have one handy

[OperationContract, WebGet]

Stream EchoText(string text)


return new AdapterStream( textWriter =>


textWriter.WriteLine("You said: ");



}, Encoding.UTF8);


Request interceptors l.jpg
Request Interceptors

  • MessageInspectors at the channel layer

  • Think of them like a per-service pipeline

  • Arbitrary message manipulation prior to dispatch; can prevent dispatch too

public class XHttpMethodOverrideInterceptor:RequestInterceptor


public override void ProcessRequest(

ref RequestContextrequestContext)


//Change the HTTP method used for dispatch based on

//the X-HTTP-Method-Override header



Webcache l.jpg

  • Integrates WCF operations with ASP.NET caching (requires ASP.NET Compat Mode)

  • Cache profile stored in Web.config

[OperationContract, WebGet]


public Atom10FeedFormatter GetFeed(inti) { … }





<add name="CacheFor1Min" duration="60"

enabled="true" location="Any" varyByParam=“i"/>





Asp net authentication support l.jpg
ASP.NET Authentication Support

  • “It just works” with ASP.NET

  • Full support for Membership + Roles

  • Requires ASP.NET Compatibility Mode

[OperationContract, WebGet]

[PrincipalPermission(SecurityAction.Demand, Role=“admin")]

SampleResponseBodyGetData(inti, string s)