SlideShare a Scribd company logo
Binu Bhasuran
Microsoft MVP Visual C#
Facebook http://facebook.com/codeno47
Blog http://proxdev.com/
• REST defines an architectural style based on a
set of constraints for building things the “Web”
way. REST is not tied to any particular
technology or platform – it’s simply a way to
design things to work like the Web.
• People often refer to services that follow this
philosophy as “RESTful services.”
On the Web, every resource is given a unique
identifier, also known as a universal resource
identifier (URI). The most common type of URI
used on the Web today is a uniform resource
locator (URL).
When you retrieve a resource using a Web
browser, you’re really retrieving a
representation of that resource.
The Web platform also comes with a standard communication
protocol – HTTP – for interacting with resources and their
representations.
The GET method allows you to retrieve a resource
representation
while PUT allows you to create or update a resource with the
supplied representation,
DELETE allows you to delete a resource.
In short, GET, PUT, and DELETE provide basic CRUD operations
(create, retrieve, update, and delete) for the Web.
HEAD and OPTIONS, on the other hand, provide the ability to
retrieve resource metadata, allowing you to discover out how
to interact with resources at run time.
Method Description Safe Idempotent
GET Requests a specific
representation of a
resource
Yes Yes
PUT Create or update a
resource with the
supplied representation
No Yes
DELETE Deletes the specified
resource
No Yes
POST Submits data to be
processed by the
identified resource
No No
HEAD Similar to GET but only
retrieves headers and not
the body
Yes Yes
OPTIONS Returns the methods
supported by the
identified resource
Yes Yes
Moving from Verbs to Nouns
Designing the URI Templates
[ServiceContract]
public partial class BookmarkService
{
...
[WebInvoke(Method = "POST", RequestFormat=WebMessageFormat.Json,
UriTemplate = "users/{username}/bookmarks?format=json")]
[OperationContract]
void PostBookmarkAsJson(string username, Bookmark newValue)
{
HandlePostBookmark(username, newValue);
}
[WebGet(ResponseFormat= WebMessageFormat.Json,
UriTemplate = "users/{username}/bookmarks/{id}?format=json")]
[OperationContract]
Bookmark GetBookmarkAsJson(string username, string id)
{
HandleGetBookmark(username, id);
}
...
}
private bool AuthenticateUser(string user)
{
WebOperationContext ctx = WebOperationContext.Current;
string requestUri =
ctx.IncomingRequest.UriTemplateMatch.RequestUri.ToString();
string authHeader =
ctx.IncomingRequest.Headers[HttpRequestHeader.Authorization];
// if supplied hash is valid, user is authenticated
if (IsValidUserKey(authHeader, requestUri))
return true;
return false;
}
public bool IsValidUserKey(string key, string uri)
{
string[] authParts = key.Split(':');
if (authParts.Length == 2)
{
string userid = authParts[0];
string hash = authParts[1];
if (ValidateHash(userid, uri, hash))
return true;
}
return false;
}
bool ValidateHash(string userid, string uri, string hash)
{
if (!UserKeys.ContainsKey(userid))
return false;
string userkey = UserKeys[userid];
byte[] secretBytes = ASCIIEncoding.ASCII.GetBytes(userkey);
HMACMD5 hmac = new HMACMD5(secretBytes);
byte[] dataBytes = ASCIIEncoding.ASCII.GetBytes(uri);
byte[] computedHash = hmac.ComputeHash(dataBytes);
string computedHashString = Convert.ToBase64String(computedHash);
return computedHashString.Equals(hash);
}
if (!AuthenticateUser(username))
{
WebOperationContext.Current.OutgoingResponse.Sta
tusCode =
HttpStatusCode.Unauthorized;
return;
}
<configuration>
<system.serviceModel>
<services>
<service name="BookmarkService">
<endpoint binding="webHttpBinding" contract="BookmarkService"
behaviorConfiguration="webHttp"/>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="webHttp">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
<configuration>
The WCF provides the attributes,
MessageContractAttribute,
MessageHeaderAttribute, and
MessageBodyMemberAttribute to describe the
structure of the SOAP messages sent and
received by a service.
[DataContract]
public class SomeProtocol
{
[DataMember]
public long CurrentValue;
[DataMember]
public long Total;
}
[DataContract]
public class Item
{
[DataMember]
public string ItemNumber;
[DataMember]
public decimal Quantity;
[DataMember]
public decimal UnitPrice;
}
[MessageContract]
public class ItemMesage
{
[MessageHeader]
public SomeProtocol ProtocolHeader;
[MessageBody]
public Item Content;
}
[ServiceContract]
public interface IItemService
{
[OperationContract]
public void DeliverItem(ItemMessage itemMessage);
}
Restful Services With WFC
http://msdn.microsoft.com/en-
us/library/ms730214.aspx
Restful Services With WFC
Restful Services With WFC

More Related Content

PPTX
Rest and Rails
PPT
Developing RESTful WebServices using Jersey
PPT
Rest in Rails
PPT
Akiban Presentation at Percona Live NYC 2012
PPTX
Introduction to RESTful Webservices in JAVA
PDF
Some REST Design Patterns (and Anti-Patterns) - SOA Symposium 2009
PDF
WordPress Café: Using WordPress as a Framework
PDF
Intoduction to php web services and json
Rest and Rails
Developing RESTful WebServices using Jersey
Rest in Rails
Akiban Presentation at Percona Live NYC 2012
Introduction to RESTful Webservices in JAVA
Some REST Design Patterns (and Anti-Patterns) - SOA Symposium 2009
WordPress Café: Using WordPress as a Framework
Intoduction to php web services and json

Viewers also liked (8)

PPTX
Design patterns
PDF
Oracle ODI & Oracle SOA installation
PPT
ASP.NET Training Syllabus Course
PDF
Dot net syllabus book
PPTX
C# Basics
PDF
Learn C# - C# .NET Tutorial PDF by Industry Expert
PDF
No pain, no gain. CSS Code Reviews FTW.
PDF
The Great State of Design with CSS Grid Layout and Friends
Design patterns
Oracle ODI & Oracle SOA installation
ASP.NET Training Syllabus Course
Dot net syllabus book
C# Basics
Learn C# - C# .NET Tutorial PDF by Industry Expert
No pain, no gain. CSS Code Reviews FTW.
The Great State of Design with CSS Grid Layout and Friends
Ad

Similar to Restful Services With WFC (20)

ODP
RESTFul WebApp Concept
ODP
RESTFul WebApp Concept
PDF
Network Device Database Management with REST using Jersey
PPTX
CodeMash 2013 Microsoft Data Stack
KEY
Routes Controllers
PDF
Multi Client Development with Spring for SpringOne 2GX 2013 with Roy Clarkson
PPTX
Are you getting Sleepy. REST in SharePoint Apps
PDF
Building RESTful applications using Spring MVC
PDF
Taking Advantage of the SharePoint 2013 REST API
PDF
Spark IT 2011 - Developing RESTful Web services with JAX-RS
PPT
Modified REST Presentation
PPTX
Web Technologies - forms and actions
PPTX
RESTful WCF Services
PDF
Building RESTful Services with WCF 4.0
PDF
[2015/2016] The REST architectural style
PDF
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
PDF
OSGi and Spring Data for simple (Web) Application Development
PPTX
Get Some Rest - Taking Advantage of the SharePoint 2013 REST API
PDF
Rapid Application Development with SwiftUI and Firebase
PPTX
Introduction to using jQuery with SharePoint
RESTFul WebApp Concept
RESTFul WebApp Concept
Network Device Database Management with REST using Jersey
CodeMash 2013 Microsoft Data Stack
Routes Controllers
Multi Client Development with Spring for SpringOne 2GX 2013 with Roy Clarkson
Are you getting Sleepy. REST in SharePoint Apps
Building RESTful applications using Spring MVC
Taking Advantage of the SharePoint 2013 REST API
Spark IT 2011 - Developing RESTful Web services with JAX-RS
Modified REST Presentation
Web Technologies - forms and actions
RESTful WCF Services
Building RESTful Services with WCF 4.0
[2015/2016] The REST architectural style
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
OSGi and Spring Data for simple (Web) Application Development
Get Some Rest - Taking Advantage of the SharePoint 2013 REST API
Rapid Application Development with SwiftUI and Firebase
Introduction to using jQuery with SharePoint
Ad

More from Binu Bhasuran (11)

PPTX
Asp.net web api
PPTX
Design patterns fast track
PDF
Microsoft Azure solutions - Whitepaper
PPTX
Microsoft Managed Extensibility Framework
PDF
Wcf development
PPTX
.Net platform an understanding
PDF
Biz talk
PDF
Moving from webservices to wcf services
PDF
Model view view model
PDF
Beginning with wcf service
PDF
Asynchronous programming in .net 4.5 with c#
Asp.net web api
Design patterns fast track
Microsoft Azure solutions - Whitepaper
Microsoft Managed Extensibility Framework
Wcf development
.Net platform an understanding
Biz talk
Moving from webservices to wcf services
Model view view model
Beginning with wcf service
Asynchronous programming in .net 4.5 with c#

Recently uploaded (20)

PPTX
Computer Software and OS of computer science of grade 11.pptx
PPTX
Why Generative AI is the Future of Content, Code & Creativity?
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PPTX
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
PPTX
GSA Content Generator Crack (2025 Latest)
PDF
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
PDF
STL Containers in C++ : Sequence Container : Vector
PDF
Salesforce Agentforce AI Implementation.pdf
PDF
DuckDuckGo Private Browser Premium APK for Android Crack Latest 2025
PPTX
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
PPTX
Oracle Fusion HCM Cloud Demo for Beginners
PDF
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
DOCX
How to Use SharePoint as an ISO-Compliant Document Management System
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PPTX
Tech Workshop Escape Room Tech Workshop
PDF
EaseUS PDF Editor Pro 6.2.0.2 Crack with License Key 2025
PDF
Ableton Live Suite for MacOS Crack Full Download (Latest 2025)
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PDF
Types of Token_ From Utility to Security.pdf
PPTX
chapter 5 systemdesign2008.pptx for cimputer science students
Computer Software and OS of computer science of grade 11.pptx
Why Generative AI is the Future of Content, Code & Creativity?
wealthsignaloriginal-com-DS-text-... (1).pdf
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
GSA Content Generator Crack (2025 Latest)
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
STL Containers in C++ : Sequence Container : Vector
Salesforce Agentforce AI Implementation.pdf
DuckDuckGo Private Browser Premium APK for Android Crack Latest 2025
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
Oracle Fusion HCM Cloud Demo for Beginners
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
How to Use SharePoint as an ISO-Compliant Document Management System
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Tech Workshop Escape Room Tech Workshop
EaseUS PDF Editor Pro 6.2.0.2 Crack with License Key 2025
Ableton Live Suite for MacOS Crack Full Download (Latest 2025)
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
Types of Token_ From Utility to Security.pdf
chapter 5 systemdesign2008.pptx for cimputer science students

Restful Services With WFC

  • 1. Binu Bhasuran Microsoft MVP Visual C# Facebook http://facebook.com/codeno47 Blog http://proxdev.com/
  • 2. • REST defines an architectural style based on a set of constraints for building things the “Web” way. REST is not tied to any particular technology or platform – it’s simply a way to design things to work like the Web. • People often refer to services that follow this philosophy as “RESTful services.”
  • 3. On the Web, every resource is given a unique identifier, also known as a universal resource identifier (URI). The most common type of URI used on the Web today is a uniform resource locator (URL). When you retrieve a resource using a Web browser, you’re really retrieving a representation of that resource.
  • 4. The Web platform also comes with a standard communication protocol – HTTP – for interacting with resources and their representations. The GET method allows you to retrieve a resource representation while PUT allows you to create or update a resource with the supplied representation, DELETE allows you to delete a resource. In short, GET, PUT, and DELETE provide basic CRUD operations (create, retrieve, update, and delete) for the Web. HEAD and OPTIONS, on the other hand, provide the ability to retrieve resource metadata, allowing you to discover out how to interact with resources at run time.
  • 5. Method Description Safe Idempotent GET Requests a specific representation of a resource Yes Yes PUT Create or update a resource with the supplied representation No Yes DELETE Deletes the specified resource No Yes POST Submits data to be processed by the identified resource No No HEAD Similar to GET but only retrieves headers and not the body Yes Yes OPTIONS Returns the methods supported by the identified resource Yes Yes
  • 6. Moving from Verbs to Nouns Designing the URI Templates
  • 7. [ServiceContract] public partial class BookmarkService { ... [WebInvoke(Method = "POST", RequestFormat=WebMessageFormat.Json, UriTemplate = "users/{username}/bookmarks?format=json")] [OperationContract] void PostBookmarkAsJson(string username, Bookmark newValue) { HandlePostBookmark(username, newValue); } [WebGet(ResponseFormat= WebMessageFormat.Json, UriTemplate = "users/{username}/bookmarks/{id}?format=json")] [OperationContract] Bookmark GetBookmarkAsJson(string username, string id) { HandleGetBookmark(username, id); } ... }
  • 8. private bool AuthenticateUser(string user) { WebOperationContext ctx = WebOperationContext.Current; string requestUri = ctx.IncomingRequest.UriTemplateMatch.RequestUri.ToString(); string authHeader = ctx.IncomingRequest.Headers[HttpRequestHeader.Authorization]; // if supplied hash is valid, user is authenticated if (IsValidUserKey(authHeader, requestUri)) return true; return false; }
  • 9. public bool IsValidUserKey(string key, string uri) { string[] authParts = key.Split(':'); if (authParts.Length == 2) { string userid = authParts[0]; string hash = authParts[1]; if (ValidateHash(userid, uri, hash)) return true; } return false; }
  • 10. bool ValidateHash(string userid, string uri, string hash) { if (!UserKeys.ContainsKey(userid)) return false; string userkey = UserKeys[userid]; byte[] secretBytes = ASCIIEncoding.ASCII.GetBytes(userkey); HMACMD5 hmac = new HMACMD5(secretBytes); byte[] dataBytes = ASCIIEncoding.ASCII.GetBytes(uri); byte[] computedHash = hmac.ComputeHash(dataBytes); string computedHashString = Convert.ToBase64String(computedHash); return computedHashString.Equals(hash); }
  • 12. <configuration> <system.serviceModel> <services> <service name="BookmarkService"> <endpoint binding="webHttpBinding" contract="BookmarkService" behaviorConfiguration="webHttp"/> </service> </services> <behaviors> <endpointBehaviors> <behavior name="webHttp"> <webHttp/> </behavior> </endpointBehaviors> </behaviors> </system.serviceModel> <configuration>
  • 13. The WCF provides the attributes, MessageContractAttribute, MessageHeaderAttribute, and MessageBodyMemberAttribute to describe the structure of the SOAP messages sent and received by a service.
  • 14. [DataContract] public class SomeProtocol { [DataMember] public long CurrentValue; [DataMember] public long Total; } [DataContract] public class Item { [DataMember] public string ItemNumber; [DataMember] public decimal Quantity; [DataMember] public decimal UnitPrice; } [MessageContract] public class ItemMesage { [MessageHeader] public SomeProtocol ProtocolHeader; [MessageBody] public Item Content; } [ServiceContract] public interface IItemService { [OperationContract] public void DeliverItem(ItemMessage itemMessage); }