30

RESTful Services for the Programmable Web with Windows Communication Foundation

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

Page 1: RESTful Services for the Programmable Web with Windows Communication Foundation
Page 2: RESTful Services for the Programmable Web with Windows Communication Foundation

RESTful Services for the Programmable Web with Windows Communication FoundationRon JacobsSr. Technical EvangelistMicrosoft Corporation

Page 3: RESTful Services for the Programmable Web with Windows Communication Foundation
Page 4: RESTful Services for the Programmable Web with Windows Communication Foundation

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

Page 5: RESTful Services for the Programmable Web with Windows Communication Foundation

How do we move from a web of pages to a web of services?

question

Page 6: RESTful Services for the Programmable Web with Windows Communication Foundation

The Web of Services should work the way the Web of Pages works

Page 7: RESTful Services for the Programmable Web with Windows Communication Foundation

RESTfullnessHI-REST LO-REST

URIHTTP verbsSemanticsFormats

Page 8: RESTful Services for the Programmable Web with Windows Communication Foundation

Industrial Strength

ComplexPowerful

Difficult

SOAP/WS-*

Specifications

Page 9: RESTful Services for the Programmable Web with Windows Communication Foundation

Light Weight

REST

Simple

Less Functional

Good Enough

Freedom

Page 10: RESTful Services for the Programmable Web with Windows Communication Foundation

SOAP

REST

WCF

Page 11: RESTful Services for the Programmable Web with Windows Communication Foundation

WCF REST Starter Kit

http://tinyurl.com/wcfRESTsk

annoucing

Page 12: RESTful Services for the Programmable Web with Windows Communication Foundation

WCF REST Starter Kit

Visual Studio 2008 templatesCachingSecurityHelp pageClient library Codeplex Project supported by WCF team

Features may be rolled into .NET 4.0

Page 13: RESTful Services for the Programmable Web with Windows Communication Foundation

Consuming Twitter

demo

Page 14: RESTful Services for the Programmable Web with Windows Communication Foundation

Resources

Page 15: RESTful Services for the Programmable Web with Windows Communication Foundation

Define Your Resource

public class SessionData{ public string ID { get; set; } public string Title { get; set; } public string Speaker { get; set; }}

Page 16: RESTful Services for the Programmable Web with Windows Communication Foundation

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

Page 17: RESTful Services for the Programmable Web with Windows Communication Foundation

Resources

URI

Page 18: RESTful Services for the Programmable Web with Windows Communication Foundation

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

Page 19: RESTful Services for the Programmable Web with Windows Communication Foundation

Resources

URI

Service

Page 20: RESTful Services for the Programmable Web with Windows Communication Foundation

Session Service

public class Session{ SessionData GetSession(string id) { return _sessions[id]; }}

Page 21: RESTful Services for the Programmable Web with Windows Communication Foundation

WCF Service

[ServiceContract]public class Session { [OperationContract] SessionData GetSession(string id) { return _sessions[id]; }}

Note: This is a SOAP Service

Page 22: RESTful Services for the Programmable Web with Windows Communication Foundation

WCF REST Service

[ServiceContract]public class Session { [OperationContract] [WebGet] SessionData GetSession(string id) { return _sessions[id]; }}Address

http://localhost/Session.svc/GetSession?id=123

Page 23: RESTful Services for the Programmable Web with Windows Communication Foundation

WCF Service

[ServiceContract]public class Session { [OperationContract] [WebGet(UriTemplate="session/{id}"] SessionData GetSession(string id) { return _sessions[id]; }}

Addresshttp://localhost/Session.svc/session/123

Page 24: RESTful Services for the Programmable Web with Windows Communication Foundation

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!

Page 25: RESTful Services for the Programmable Web with Windows Communication Foundation

Session Service

demo

Page 26: RESTful Services for the Programmable Web with Windows Communication Foundation

Future Help Page

Page 27: RESTful Services for the Programmable Web with Windows Communication Foundation

No SVC Configuration

<configuration><system.serviceModel>     <serviceHostingEnvironment><serviceActivations><add virtualPath="~/wines”factory="System.ServiceModel.Activation.WebServiceHostFactory” service=“CohoWinery.Wines"/>

Microsoft Confidential

Page 28: RESTful Services for the Programmable Web with Windows Communication Foundation

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

Page 29: RESTful Services for the Programmable Web with Windows Communication Foundation
Page 30: RESTful Services for the Programmable Web with Windows Communication Foundation

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