1 / 20

Building RESTful Services using WCF

Building RESTful Services using WCF. Jon Flanders http://www.rest-ful.net / INT303. About Me. Jon Flanders – http://www.rest-ful.net/ Independent consultant/trainer BizTalk MVP. Storytime: Once upon time …. REST. Representational State Transfer introduced by Roy Fielding

heba
Télécharger la présentation

Building RESTful Services using WCF

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Building RESTful Services using WCF Jon Flanders http://www.rest-ful.net/ INT303

  2. About Me • Jon Flanders – http://www.rest-ful.net/ • Independent consultant/trainer • BizTalk MVP

  3. Storytime: Once upon time…

  4. REST • Representational State Transfer • introduced by Roy Fielding • Architectural style • A set of constraints distilled from the architecture of the Web • URIs represent resources • Clients 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 More to come from Microsoft and others – but why let them have all the fun (and rewards)? ADO.NET Data Services EVERYBODY that isn’t Microsoft (Twitter,Google, Yahoo, Facebook, MySpace)

  6. REST Advantages • GET responses can be cached • Using URIs build on experience using the Web • Uniform interface simplifies building and using services • Statelessness constraint eases scalability • GET is safe, can be called N times without causing change • PUT 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 resource • Determine what part of the uniform interface each resource should implement

  8. Uniform Interface

  9. Windows Communication Foundation (WCF) • Framework for building applications that communicate • Client-Server • Message oriented • Service oriented • WCF abstracts away network complexities, developer concentrates on code • Most of WCF is highly geared toward SOAP • REST 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 messages • SOAP support in 3.0/3.5 routes messages to methods based on SOAP Action • URI always the same • Always uses POST • Done by the default dispatcher

  11. WCF 3.5 Web Programming • Messages are routed to methods based on: • URI • HTTP Verb • Same programming model as “SOAP” • ServiceContract, OperationContract, DataContract • New dispatcher that maps URIs/Verbs to methods

  12. WCF 3.5 REST infrastructure • UriTemplate & UriTemplateTable • URI parsing • WebGet & WebInvoke attributes • UriTemplate defines URI • WebGet + UriTemplate maps GET requests to methods • WebInvoke + UriTemplate maps remainder of uniform interface to methods , Method property determines verb (POST is default) • WebHttpBinding/WebServiceHost/WebServiceHostFactory • Eases use and configuration

  13. WCF Dispatching Network Transport Channel Transport Channel (HTTP) Message Message Encoder Message Encoder (Text + No SOAP) Protocol Channel (1-N) Dispatcher (URI + VERB) Dispatcher (Action) Your Code

  14. AJAX Support • Many RESTful clients are JavaScript based AJAX clients • JavaScript Object Notation (JSON) is the preferred resource representation • Smaller footprint than XML • No parsing necessary • WCF has support for AJAX applications at two levels • JSONDataContractSerializer for JSON parsing and generation • JavaScript “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 OM • OM 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 services • Builds on the existing architecture of the web • WCF 3.5 adds support for this architecture

  19. Complete an evaluation on CommNet and enter to win an Xbox 360 Elite!

  20. Required Slide © 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.

More Related