Upload
goodfriday
View
1.239
Download
0
Embed Size (px)
DESCRIPTION
Services are needed to light up the Web, and Windows Communication Foundation (WCF) makes it possible to build RESTful services more quickly and easily than ever before by using the new WCF REST Starter Kit. In this session, we demonstrate using WCF to build a simple REST Service through to advanced REST concepts of Addressability, Scalability, and Security.
Citation preview
RESTful Services for the Programmable Web with Windows Communication FoundationRon JacobsSr. Technical EvangelistMicrosoft Corporation
Why the Web Works
Simple and openAddressing scheme – URIApplication protocol – HTTPRepresentation Format – (X)HTMLResponse codes – HTTP status
Scales best when StatelessCached
It works because people find value in it
How do we move from a web of pages to a web of services?
question
The Web of Services should work the way the Web of Pages works
RESTfullnessHI-REST LO-REST
URIHTTP verbsSemanticsFormats
Industrial Strength
ComplexPowerful
Difficult
SOAP/WS-*
Specifications
Light Weight
REST
Simple
Less Functional
Good Enough
Freedom
SOAP
REST
WCF
WCF REST Starter Kit
http://tinyurl.com/wcfRESTsk
annoucing
WCF REST Starter Kit
Visual Studio 2008 templatesCachingSecurityHelp pageClient library Codeplex Project supported by WCF team
Features may be rolled into .NET 4.0
Consuming Twitter
demo
Resources
Define Your Resource
public class SessionData{ public string ID { get; set; } public string Title { get; set; } public string Speaker { get; set; }}
Resource Format
Content negotiationAllow the client to ask for the format they want
text/xmlSupported (default)
application/jsonSupported
Methods.xml, .jsonQuery parameter ?format=jsonAccept Header
Resources
URI
Resource URI
URI Template HTTP Method
Operation
Session.svc/ GET Get all sessions
Session.svc/{id} GET Get one session
Session.svc/ POST Add a new session
Session.svc/{id} PUT Update a session
Session.svc/{id} DELETE Delete
Resources
URI
Service
Session Service
public class Session{ SessionData GetSession(string id) { return _sessions[id]; }}
WCF Service
[ServiceContract]public class Session { [OperationContract] SessionData GetSession(string id) { return _sessions[id]; }}
Note: This is a SOAP Service
WCF REST Service
[ServiceContract]public class Session { [OperationContract] [WebGet] SessionData GetSession(string id) { return _sessions[id]; }}Address
http://localhost/Session.svc/GetSession?id=123
WCF Service
[ServiceContract]public class Session { [OperationContract] [WebGet(UriTemplate="session/{id}"] SessionData GetSession(string id) { return _sessions[id]; }}
Addresshttp://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!
Session Service
demo
Future Help Page
No SVC Configuration
<configuration><system.serviceModel> <serviceHostingEnvironment><serviceActivations><add virtualPath="~/wines”factory="System.ServiceModel.Activation.WebServiceHostFactory” service=“CohoWinery.Wines"/>
Microsoft Confidential
What Now?
Download the WCF REST Starter Kithttp://msdn.microsoft.com/wcf/rest
Download the REST Starter Kit Labshttp://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.