300 likes | 463 Views
RESTful Services for the Programmable Web with Windows Communication Foundation. Ron Jacobs Sr. Technical Evangelist Microsoft Corporation. Why the Web Works. Simple and open Addressing scheme – URI Application protocol – HTTP Representation Format – (X)HTML Response codes – HTTP status
E N D
RESTful Services for the Programmable Web with Windows Communication Foundation Ron Jacobs Sr. Technical Evangelist Microsoft Corporation
Why the Web Works • Simple and open • Addressing scheme – URI • Application protocol – HTTP • Representation Format – (X)HTML • Response codes – HTTP status • Scales best when • Stateless • Cached • It works because people find value in it
question How do we move from a web of pages to a web of services?
The Web of Services should work the way the Web of Pages works
RESTfullness HI-REST LO-REST URI HTTP verbs Semantics Formats
SOAP/WS-* Industrial Strength Complex Powerful Difficult Specifications
REST Simple Light Weight Good Enough Less Functional Freedom
REST WCF SOAP
annoucing WCF REST Starter Kit http://tinyurl.com/wcfRESTsk
WCF REST Starter Kit • Visual Studio 2008 templates • Caching • Security • Help page • Client library • Codeplex Project supported by WCF team • Features may be rolled into .NET 4.0
demo Consuming Twitter
Define Your Resource • public class SessionData • { • public string ID { get; set; } • public string Title { get; set; } • public string Speaker { get; set; } • }
Resource Format • Content negotiation • Allow the client to ask for the format they want • text/xml • Supported (default) • application/json • Supported • Methods • .xml, .json • Query parameter ?format=json • Accept Header
URI Resources
Service URI Resources
Session Service • public class Session • { • SessionDataGetSession(string id) • { • return _sessions[id]; • } • }
WCF Service • [ServiceContract] • public class Session • { • [OperationContract] • SessionDataGetSession(string id) • { • return _sessions[id]; • } • } Note: This is a SOAP Service
WCF REST Service • [ServiceContract] • public class Session • { • [OperationContract] • [WebGet] • SessionDataGetSession(string id) • { • return _sessions[id]; • } • } Address http://localhost/Session.svc/GetSession?id=123
WCF Service • [ServiceContract] • public class Session • { • [OperationContract] • [WebGet(UriTemplate="session/{id}"] • SessionDataGetSession(string id) • { • return _sessions[id]; • } • } Address http://localhost/Session.svc/session/123
Session.svc • <%@ ServiceHost • Language="C#" • Debug="true" • Service="Conference.Session" • CodeBehind="Session.svc.cs" • Factory="System.ServiceModel.Activation. • WebServiceHostFactory" • %> No <System.ServiceModel> in web.config!
demo Session Service
Microsoft Confidential No SVC Configuration • <configuration> • <system.serviceModel> • <serviceHostingEnvironment> • <serviceActivations> • <add virtualPath="~/wines” • factory= • "System.ServiceModel.Activation. • WebServiceHostFactory” service=“CohoWinery.Wines"/>
What Now? • Download the WCF REST Starter Kit • http://msdn.microsoft.com/wcf/rest • Download the REST Starter Kit Labs • http://code.msdn.microsoft.com/wcfrestlabs • Give it a try
© 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.