creating a restful api with windows communication foundation

23
Creating a RESTful API with WCF Aaron Sloman, speakTECH Haider Sabri, speakTECH

Upload: goodfriday

Post on 29-Jun-2015

1.012 views

Category:

Technology


1 download

DESCRIPTION

Learn how MySpace used Windows Communication Foundation and .NET 3.5 to rapidly scale up a massive RESTful API infrastructure that process millions of requests a day

TRANSCRIPT

Page 1: Creating a RESTful API with Windows Communication Foundation

Creating a RESTful API with WCFAaron Sloman, speakTECHHaider Sabri, speakTECH

Page 2: Creating a RESTful API with Windows Communication Foundation

About this presentation…

BackgroundREST (Representational State Transfer)

What does it mean to be RESTful?Why REST?

WCFHow does WCF support REST?What are the pieces we need to add?

ChessA RESTful Chess API

Page 3: Creating a RESTful API with Windows Communication Foundation

Background

Open Your API – 2005MySpace API roadmapWhere are we today ?

developer.myspace.com

Page 4: Creating a RESTful API with Windows Communication Foundation

Requirements for the Service

Public interface for 3rd party clients and partners to view, add, update, delete data.Easily consumable by any clientFollows established industry standardsNeeds to be highly scalableSupports different data interchange formatsModerately securable

Page 5: Creating a RESTful API with Windows Communication Foundation

Solution

Test’s we did….

WCFREST

Page 6: Creating a RESTful API with Windows Communication Foundation

Resource Oriented ArchitectureWhat does it mean to be RESTful?Power combo: URI and HTTP Method

Addressable, hierarchical URIs represent the entities or objects on your APIHTTP Method represents the action to be taken on the resource

Connectedness and DiscoverabilityLike the Web, Http Responses contain links to other resources

Roy Fielding dissertation http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm

Page 7: Creating a RESTful API with Windows Communication Foundation

Why REST?

Benefits of REST for Web APIsLow barrier of entryROA follows Web Semantics…convenient for Web Service APIs.Flexibility in Response formats

REST is best choice when creating a general API when clients are unknown

Page 8: Creating a RESTful API with Windows Communication Foundation

A RESTful API in Action

demo

Page 9: Creating a RESTful API with Windows Communication Foundation

WCF Support for ROAThe “Web Programming Model”

URI Templates & WebGet/WebInvokeAttribute based definitions of URI template and HTTP method provide mapping of incoming request URIs to methods

WebHttpBindingThe binding that enables above

WebOperationContextFor more information:

Building Applications and Services with .NET Framework 3.5San Polo 3501A, M10:15 AM March 6th

Page 10: Creating a RESTful API with Windows Communication Foundation

RESTChess behind the scenes…RESTChess.com

demo

Page 11: Creating a RESTful API with Windows Communication Foundation

The pieces we need to addThe 20%

Flexible URIsBridging Low REST clientsRequest Authentication via Digital SigningExtending WebOperationContextMultiple Representation FormatsRESTful Exception Handling

Page 12: Creating a RESTful API with Windows Communication Foundation

URI Template shortcomingsProblems…

Service .svc extensionRequired when hosting a WCF service in IIS

Can’t use custom extensions in templates

What if I want to let the URI extension define the representation format?

Page 13: Creating a RESTful API with Windows Communication Foundation

URI Template shortcomingsSolutions…

Use URL Rewriter implemented as an HttpModule

Add .svc service file to incoming request URIUse extension format in path hierarchy and rewrite URI accordingly

Page 14: Creating a RESTful API with Windows Communication Foundation

URLRewriting via IIS7

demo

Page 15: Creating a RESTful API with Windows Communication Foundation

High/Low REST with the same service

High: support for full set of HTTP methodsLow: only support GET and POSTAllow clients to override HTTP method

Using X-HTTPMethodOverride headerUse of _method query parameter

Extending WCF…Channels to the Rescue

Page 16: Creating a RESTful API with Windows Communication Foundation

High/Low REST

Extending WCF via Custom Channel

demo

Page 17: Creating a RESTful API with Windows Communication Foundation

Request AuthenticationOAuth

Introducing OAuthStandards based API authentication

Standard access delegation between Consumer and ProviderStandard digital signing mechanismoauth.net

Page 18: Creating a RESTful API with Windows Communication Foundation

Request AuthenticationOAuth

WCF Custom Channels to the rescue again

Channel will authenticate request before method dispatch

Extend Context with application data

Page 19: Creating a RESTful API with Windows Communication Foundation

OAuth

Extending WCF via Custom Channel

demo

Page 20: Creating a RESTful API with Windows Communication Foundation

RIA consumes RestChess

demo

Page 21: Creating a RESTful API with Windows Communication Foundation

Summary

MySpace Development Platform is RESTfulWCF is a powerful web API development platformWCF has great extension pointsAll demo source available at RestChess.com

MySpace API’s are availableVisit developer.myspace.com

Page 22: Creating a RESTful API with Windows Communication Foundation

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

Page 23: Creating a RESTful API with Windows Communication Foundation