Upload
darleen-lynch
View
221
Download
0
Tags:
Embed Size (px)
Citation preview
Building RESTful Services using WCF
Jon Flandershttp://www.rest-ful.net/INT303
About Me Jon Flanders –
http://www.rest-ful.net/
Independent consultant/trainer
BizTalk MVP
3
Storytime: Once upon time…
4
REST
Representational State Transferintroduced by Roy Fielding
Architectural styleA set of constraints distilled from the architecture of the Web
URIs represent resourcesClients interact via with resources via a uniform interface (GET, POST, PUT, DELETE)Services are stateless
5
Why should you care?
Microsoft Live Services .NET Services
ADO.NET Data Services
EVERYBODY that isn’t Microsoft (Twitter,Google,
Yahoo, Facebook, MySpace)
More to come from Microsoft and others – but why let them have all the
fun (and rewards)?
6
REST Advantages
GET responses can be cachedUsing URIs build on experience using the WebUniform interface simplifies building and using servicesStatelessness constraint eases scalabilityGET is safe, can be called N times without causing changePUT and DELETE are idempotent (same effect no matter how many times called)
7
Building a RESTful service
Design your resource(s)Determine the URI for each resourceDetermine what part of the uniform interface each resource should implement
8
Uniform Interface
•Retrieves a resource
•Guaranteed not to cause side-effects (SAFE)
•Results are cacheable
GET
•Creates a new resource
•Unsafe: effect of this verb isn’t defined by HTTP
POST
•Updates an existing resource
•Used for resource creation when client knows URI
•Can call N times, same thing will always happen (idempotent)
PUT
•Removes a resource
•Can call N times, same thing will always happen (idempotent)
DELETE
9
Windows Communication Foundation (WCF)
Framework for building applications that communicate
Client-ServerMessage orientedService oriented
WCF abstracts away network complexities, developer concentrates on codeMost of WCF is highly geared toward SOAPREST support added in 3.5 and improved in 3.5 sp1
10
WCF Messages to Methods
In WCF developers write methods in classes that respond to network messagesSOAP support in 3.0/3.5 routes messages to methods based on SOAP Action
URI always the sameAlways uses POST
Done by the default dispatcher
11
WCF 3.5 Web Programming
Messages are routed to methods based on:URIHTTP Verb
Same programming model as “SOAP”ServiceContract, OperationContract, DataContract
New dispatcher that maps URIs/Verbs to methods
12
WCF 3.5 REST infrastructureUriTemplate & UriTemplateTable
URI parsing WebGet & WebInvoke attributes
UriTemplate defines URI WebGet + UriTemplate maps GET requests to methodsWebInvoke + UriTemplate maps remainder of uniform interface to methods , Method property determines verb (POST is default)
WebHttpBinding/WebServiceHost/WebServiceHostFactory
Eases use and configuration
WCF Dispatching
Network
Message
Transport Channel
Message Encoder
Protocol Channel (1-N)
Your Code
Dispatcher(Action)
Dispatcher(URI + VERB)
Transport Channel(HTTP)
Message Encoder(Text + No SOAP)
14
AJAX Support
Many RESTful clients are JavaScript based AJAX clientsJavaScript Object Notation (JSON) is the preferred resource representation
Smaller footprint than XMLNo parsing necessary
WCF has support for AJAX applications at two levels
JSONDataContractSerializer for JSON parsing and generationJavaScript “proxy” build on ASP.NET AJAX
15
Web Feeds
Web Feeds are endpoints that expose machine consumable resource representations
Commonly used for web logs (blogs), news etc.Expansion into enterprise data is happening
16
WCF support for Feeds
Built on top of WCF REST support (WebGet/UriTemplate)Feed specific feature is feed-format neutral object model
Transform your data into the WCF OMOM serialized to either RSS or Atom (or other future formats – extensible formatting capabilities)OM is closer to Atom model (Atom is richer than RSS)
17
Know the rules, bend when necessary
“…REST isn’t an all or nothing proposition. One can get significant value from partial adoption. “ Sam Ruby - Author RESTFul Web Services
Don’t underestimate the power of GET!
18
Summary
REST is an architectural style that encourages interoperable, scalable web servicesBuilds on the existing architecture of the webWCF 3.5 adds support for this architecture
Complete an evaluation on CommNet and enter to win an Xbox 360 Elite!
© 2009 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.