SlideShare a Scribd company logo
Building RESTful Services with
                         WCF
                        Aaron Skonnard
                   Cofounder, Pluralsight
Overview
Why REST?
Why REST?

1. Most folks don't need SOAP's key features
     Transport-neutrality
     Advanced WS-* protocols
     Basic SOAP is just like REST but w/out the benefits
Why REST?

2. REST is simple and the interface is uniform
     It's just HTTP + XML/JSON/XHTML
     Uniform interface that everyone understands
     Therefore, it’s more interoperable!
REST is not RPC

SOAP emphasizes verbs while REST emphasizes nouns or
"resources"
SOAP                        REST                          With REST, you define
                                                                resources,
 getUser()                                             and use a uniform interface to
 addUser()                   User { }                  operate on them (HTTP verbs)
 removeUser()                Location { }
 ...
 getLocation()                                             XML representation
 addLocation()
 ...                         <user>
                               <name>Jane User</name>
 With SOAP, you define         <gender>female</gender>
custom operations (new         <location href="http://example.org/locations/us/ny/nyc"
                               >New York City, NY, US</location>
verbs), tunnels through
                             </user>
          POST
Is REST too simple for complex systems?
Why REST?

3. REST is how the Web works
     It scales from HTTP's built-in caching mechanisms
     Caching, bookmarking, navigating/links, SSL, etc
     You can access most REST services with a browser
REST in WCF
Windows Communication Foundation

WCF doesn't take sides – it provides a unified programming
model
   And allows you to use SOAP, POX, REST, whatever data format, etc


           Architecture: SOAP, REST, distributed objects, etc

               Transport Protocol: HTTP, TCP, MSMQ, etc
 WCF
             Message format: XML, RSS, JSON, binary, etc

                   Message protocols: WS-*, none, etc
WCF programming styles

Most of the built-in WCF bindings use SOAP & WS-* by default
   You have to configure them to disable SOAP
WCF 3.5 comes with a new Web (REST) programming model
   Found in System.ServiceModel.Web.dll
   Allows you to map HTTP requests to methods via URI templates
You enable the Web model with a new binding/behavior
   Apply to messaging layer using WebHttpBinding
   Apply to dispatcher using WebHttpBehavior
WebServiceHost

     WebServiceHost simplifes hosting Web-based services
        Derives from ServiceHost and overrides OnOpening
        Automatically adds endpoint for the base address using
        WebHttpBinding
        Automatically adds WebHttpBehavior to the endpoint

               ...
 this host     WebServiceHost host = new WebServiceHost(
 adds the          typeof(EvalService),
Web binding        new Uri("http://localhost:8080/evals"));
& behavior     host.Open(); // service is up and running
               Console.ReadLine(); // hold process open
               ...

     <%@ ServiceHost Language="C#" Service="EvalService" Factory=
         "System.ServiceModel.Activation.WebScriptServiceFactory" %>
WebGetAttribute

WebGetAttribute maps HTTP GET requests to a WCF method
   Supply a UriTemplate to defining URI mapping
   The UriTemplate variables map to method parameters by name
   BodyStyle property controls bare vs. wrapped
   Request/ResponseFormat control body format
                                               URI template

[ServiceContract]
public interface IEvalService
{
    [WebGet(UriTemplate="evals?name={name}&score={score}")]
    [OperationContract]
    List<Eval> GetEvals(string name, int score);
...
WebInvokeAttribute

WebInvokeAttribute maps all other HTTP verbs to WCF
methods
   Adds a Method property for specifying the verb (default is POST)
   Allows mapping UriTemplate variables
                                                 Specify which
   Body is deserialized into remaining parameter HTTP verb this
                                                  responds to

 [ServiceContract]
 public interface IEvals
 {
     [WebInvoke(UriTemplate ="/evals?name={name}",Method="PUT")]
     [OperationContract]
     void SubmitEval(string name, Eval eval /* body */);
 ...
WebOperationContext

Use WebOperationContext to access HTTP specifics within
methods
   To retreived the current context use WebOperationContext.Current
   Provides properties for incoming/outgoing request/response context
Each context object surfaces most common HTTP details
   URI, ContentLength, ContentType, Headers, ETag, etc
WebMessageFormat

WCF provides support for two primary Web formats: XML &
JSON
   You control the format via RequestFormat and ResponseFormat

  [ServiceContract]
  public interface IEvals
  {
      [WebGet(UriTemplate = "/evals?name={nameFilter}",
          ResponseFormat = WebMessageFormat.Json)]
      [OperationContract]
      List<Eval> GetCurrentEvals(string nameFilter);
  ...

                               Specify the message format
Syndication programming model

    WCF comes with a simplified syndication programming model
       The logical data model for a feed is SyndicationFeed
       You can use it to produce/consume feeds in a variety of formats
    You use a SyndicationFeedFormatter to work with a specific
    format
       Use Atom10FeedFormatter or RSS20FeedFormatter today
                       [ServiceKnownType(typeof(Atom10FeedFormatter))]
                       [ServiceKnownType(typeof(Rss20FeedFormatter))]
                       [ServiceContract]
                       public interface IEvalService {
                           [WebGet(UriTemplate = "evalsfeed")]
                           [OperationContract]
allows you to return
                           SyndicationFeedFormatter GetEvalsFeed();
an Atom or RSS feed    ...
                       }
New in 4.0
Improved REST Support

Many features in the WCF REST Starter Kit are now part of WCF
4.0
Automatic help page

WCF 4 provides an automatic help page for REST services
   Configure the <webHttp> behavior with helpEnabled=“true”
Message format selection

WCF 4 also provides automatic format selection for XML/JSON
   This feature is built on the HTTP “Accept” headers



<configuration>
  <system.serviceModel>
    <standardEndpoints>
      <webHttpEndpoint>
        <standardEndpoint name="" helpEnabled="true"
            automaticFormatSelectionEnabled="true"/>
      </webHttpEndpoint>
    </standardEndpoints>
  </system.serviceModel>
</configuration>
Http caching support

WCF 4 provides a simpler model for managing HTTP caching
   They built on the ASP.NET caching profile architecture
   You define an [AspNetCacheProfile] for your GET operations
   Shields you from dealing with HTTP caching headers yourself



     [AspNetCacheProfile("CacheFor60Seconds")]
     [WebGet(UriTemplate=XmlItemTemplate)]
     [OperationContract]
     public Counter GetItemInXml()
     {
         return HandleGet();
     }
REST project templates

Download the new REST project templates via the new Visual
Studio 2010 Extension Manager (Tools | Extension Manager)
What about
 OData?
WCF Web Api
  Futures
http://wcf.codeplex.com

More Related Content

What's hot

Windows Communication Foundation (WCF)
Windows Communication Foundation (WCF)Windows Communication Foundation (WCF)
Windows Communication Foundation (WCF)
Betclic Everest Group Tech Team
 
WCF And ASMX Web Services
WCF And ASMX Web ServicesWCF And ASMX Web Services
WCF And ASMX Web Services
Manny Siddiqui MCS, MBA, PMP
 
WCF (Windows Communication Foundation)
WCF (Windows Communication Foundation)WCF (Windows Communication Foundation)
WCF (Windows Communication Foundation)ipower softwares
 
introduction to Windows Comunication Foundation
introduction to Windows Comunication Foundationintroduction to Windows Comunication Foundation
introduction to Windows Comunication Foundation
redaxe12
 
WCF
WCFWCF
Introduction to WCF
Introduction to WCFIntroduction to WCF
Introduction to WCF
ybbest
 
Windows Communication Foundation (WCF) Service
Windows Communication Foundation (WCF) ServiceWindows Communication Foundation (WCF) Service
Windows Communication Foundation (WCF) Service
Sj Lim
 
WCF Introduction
WCF IntroductionWCF Introduction
WCF Introduction
Mohamed Zakarya Abdelgawad
 
1. WCF Services - Exam 70-487
1. WCF Services - Exam 70-4871. WCF Services - Exam 70-487
1. WCF Services - Exam 70-487Bat Programmer
 
Enjoying the Move from WCF to the Web API
Enjoying the Move from WCF to the Web APIEnjoying the Move from WCF to the Web API
Enjoying the Move from WCF to the Web API
Kevin Hazzard
 
Session 1: The SOAP Story
Session 1: The SOAP StorySession 1: The SOAP Story
Session 1: The SOAP Story
ukdpe
 
Web API or WCF - An Architectural Comparison
Web API or WCF - An Architectural ComparisonWeb API or WCF - An Architectural Comparison
Web API or WCF - An Architectural Comparison
Adnan Masood
 
Web services, WCF services and Multi Threading with Windows Forms
Web services, WCF services and Multi Threading with Windows FormsWeb services, WCF services and Multi Threading with Windows Forms
Web services, WCF services and Multi Threading with Windows Forms
Peter Gfader
 
Web Services (SOAP, WSDL, UDDI)
Web Services (SOAP, WSDL, UDDI)Web Services (SOAP, WSDL, UDDI)
Web Services (SOAP, WSDL, UDDI)
Peter R. Egli
 
Advancio, Inc. Academy: Web Sevices, WCF & SOAPUI
Advancio, Inc. Academy: Web Sevices, WCF & SOAPUIAdvancio, Inc. Academy: Web Sevices, WCF & SOAPUI
Advancio, Inc. Academy: Web Sevices, WCF & SOAPUI
Advancio
 
Intro to web services
Intro to web servicesIntro to web services
Intro to web servicesNeil Ghosh
 

What's hot (20)

Windows Communication Foundation (WCF) Best Practices
Windows Communication Foundation (WCF) Best PracticesWindows Communication Foundation (WCF) Best Practices
Windows Communication Foundation (WCF) Best Practices
 
Windows Communication Foundation (WCF)
Windows Communication Foundation (WCF)Windows Communication Foundation (WCF)
Windows Communication Foundation (WCF)
 
Wcf
WcfWcf
Wcf
 
WCF And ASMX Web Services
WCF And ASMX Web ServicesWCF And ASMX Web Services
WCF And ASMX Web Services
 
WCF (Windows Communication Foundation)
WCF (Windows Communication Foundation)WCF (Windows Communication Foundation)
WCF (Windows Communication Foundation)
 
WCF for begineers
WCF  for begineersWCF  for begineers
WCF for begineers
 
introduction to Windows Comunication Foundation
introduction to Windows Comunication Foundationintroduction to Windows Comunication Foundation
introduction to Windows Comunication Foundation
 
WCF
WCFWCF
WCF
 
Introduction to WCF
Introduction to WCFIntroduction to WCF
Introduction to WCF
 
Windows Communication Foundation (WCF) Service
Windows Communication Foundation (WCF) ServiceWindows Communication Foundation (WCF) Service
Windows Communication Foundation (WCF) Service
 
WCF Introduction
WCF IntroductionWCF Introduction
WCF Introduction
 
WCF
WCFWCF
WCF
 
1. WCF Services - Exam 70-487
1. WCF Services - Exam 70-4871. WCF Services - Exam 70-487
1. WCF Services - Exam 70-487
 
Enjoying the Move from WCF to the Web API
Enjoying the Move from WCF to the Web APIEnjoying the Move from WCF to the Web API
Enjoying the Move from WCF to the Web API
 
Session 1: The SOAP Story
Session 1: The SOAP StorySession 1: The SOAP Story
Session 1: The SOAP Story
 
Web API or WCF - An Architectural Comparison
Web API or WCF - An Architectural ComparisonWeb API or WCF - An Architectural Comparison
Web API or WCF - An Architectural Comparison
 
Web services, WCF services and Multi Threading with Windows Forms
Web services, WCF services and Multi Threading with Windows FormsWeb services, WCF services and Multi Threading with Windows Forms
Web services, WCF services and Multi Threading with Windows Forms
 
Web Services (SOAP, WSDL, UDDI)
Web Services (SOAP, WSDL, UDDI)Web Services (SOAP, WSDL, UDDI)
Web Services (SOAP, WSDL, UDDI)
 
Advancio, Inc. Academy: Web Sevices, WCF & SOAPUI
Advancio, Inc. Academy: Web Sevices, WCF & SOAPUIAdvancio, Inc. Academy: Web Sevices, WCF & SOAPUI
Advancio, Inc. Academy: Web Sevices, WCF & SOAPUI
 
Intro to web services
Intro to web servicesIntro to web services
Intro to web services
 

Similar to Building RESTful Services with WCF 4.0

Building+restful+webservice
Building+restful+webserviceBuilding+restful+webservice
Building+restful+webservicelonegunman
 
Developing RESTful WebServices using Jersey
Developing RESTful WebServices using JerseyDeveloping RESTful WebServices using Jersey
Developing RESTful WebServices using Jerseyb_kathir
 
Jax ws
Jax wsJax ws
Jax ws
F K
 
Webservices in SalesForce (part 1)
Webservices in SalesForce (part 1)Webservices in SalesForce (part 1)
Webservices in SalesForce (part 1)
Mindfire Solutions
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
BG Java EE Course
 
SharePoint Alerts with WCF and jQuery
SharePoint Alerts with WCF and jQuerySharePoint Alerts with WCF and jQuery
SharePoint Alerts with WCF and jQuery
Nick Hadlee
 
Java servlets
Java servletsJava servlets
Java servlets
yuvarani p
 
JAX-RS 2.0 and OData
JAX-RS 2.0 and ODataJAX-RS 2.0 and OData
JAX-RS 2.0 and OData
Anil Allewar
 
Http Server Programming in JAVA - Handling http requests and responses
Http Server Programming in JAVA - Handling http requests and responsesHttp Server Programming in JAVA - Handling http requests and responses
Http Server Programming in JAVA - Handling http requests and responses
bharathiv53
 
Wcf remaining
Wcf remainingWcf remaining
Wcf remaining
shamsher ali
 
Android ax app wcf
Android ax app wcfAndroid ax app wcf
Android ax app wcf
Aravindharamanan S
 
Servlets
ServletsServlets
Android+ax+app+wcf
Android+ax+app+wcfAndroid+ax+app+wcf
Android+ax+app+wcf
Aravindharamanan S
 
Automated testing web services - part 1
Automated testing web services - part 1Automated testing web services - part 1
Automated testing web services - part 1
Aleh Struneuski
 
CodeMash 2013 Microsoft Data Stack
CodeMash 2013 Microsoft Data StackCodeMash 2013 Microsoft Data Stack
CodeMash 2013 Microsoft Data Stack
Mike Benkovich
 
Rest Service In Mule
Rest Service In Mule Rest Service In Mule
Rest Service In Mule
ChittipoluKeshav
 
JavaEE6 my way
JavaEE6 my wayJavaEE6 my way
JavaEE6 my way
Nicola Pedot
 
Jsp/Servlet
Jsp/ServletJsp/Servlet
Jsp/Servlet
Sunil OS
 

Similar to Building RESTful Services with WCF 4.0 (20)

Building+restful+webservice
Building+restful+webserviceBuilding+restful+webservice
Building+restful+webservice
 
Developing RESTful WebServices using Jersey
Developing RESTful WebServices using JerseyDeveloping RESTful WebServices using Jersey
Developing RESTful WebServices using Jersey
 
Jax ws
Jax wsJax ws
Jax ws
 
Webservices in SalesForce (part 1)
Webservices in SalesForce (part 1)Webservices in SalesForce (part 1)
Webservices in SalesForce (part 1)
 
RESTful WCF Services
RESTful WCF ServicesRESTful WCF Services
RESTful WCF Services
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
SharePoint Alerts with WCF and jQuery
SharePoint Alerts with WCF and jQuerySharePoint Alerts with WCF and jQuery
SharePoint Alerts with WCF and jQuery
 
Java servlets
Java servletsJava servlets
Java servlets
 
Servlets
ServletsServlets
Servlets
 
JAX-RS 2.0 and OData
JAX-RS 2.0 and ODataJAX-RS 2.0 and OData
JAX-RS 2.0 and OData
 
Http Server Programming in JAVA - Handling http requests and responses
Http Server Programming in JAVA - Handling http requests and responsesHttp Server Programming in JAVA - Handling http requests and responses
Http Server Programming in JAVA - Handling http requests and responses
 
Wcf remaining
Wcf remainingWcf remaining
Wcf remaining
 
Android ax app wcf
Android ax app wcfAndroid ax app wcf
Android ax app wcf
 
Servlets
ServletsServlets
Servlets
 
Android+ax+app+wcf
Android+ax+app+wcfAndroid+ax+app+wcf
Android+ax+app+wcf
 
Automated testing web services - part 1
Automated testing web services - part 1Automated testing web services - part 1
Automated testing web services - part 1
 
CodeMash 2013 Microsoft Data Stack
CodeMash 2013 Microsoft Data StackCodeMash 2013 Microsoft Data Stack
CodeMash 2013 Microsoft Data Stack
 
Rest Service In Mule
Rest Service In Mule Rest Service In Mule
Rest Service In Mule
 
JavaEE6 my way
JavaEE6 my wayJavaEE6 my way
JavaEE6 my way
 
Jsp/Servlet
Jsp/ServletJsp/Servlet
Jsp/Servlet
 

More from Saltmarch Media

Concocting an MVC, Data Services and Entity Framework solution for Azure
Concocting an MVC, Data Services and Entity Framework solution for AzureConcocting an MVC, Data Services and Entity Framework solution for Azure
Concocting an MVC, Data Services and Entity Framework solution for Azure
Saltmarch Media
 
Caring about Code Quality
Caring about Code QualityCaring about Code Quality
Caring about Code Quality
Saltmarch Media
 
Learning Open Source Business Intelligence
Learning Open Source Business IntelligenceLearning Open Source Business Intelligence
Learning Open Source Business Intelligence
Saltmarch Media
 
Java EE 7: the Voyage of the Cloud Treader
Java EE 7: the Voyage of the Cloud TreaderJava EE 7: the Voyage of the Cloud Treader
Java EE 7: the Voyage of the Cloud Treader
Saltmarch Media
 
Is NoSQL The Future of Data Storage?
Is NoSQL The Future of Data Storage?Is NoSQL The Future of Data Storage?
Is NoSQL The Future of Data Storage?
Saltmarch Media
 
Introduction to WCF RIA Services for Silverlight 4 Developers
Introduction to WCF RIA Services for Silverlight 4 DevelopersIntroduction to WCF RIA Services for Silverlight 4 Developers
Introduction to WCF RIA Services for Silverlight 4 Developers
Saltmarch Media
 
Integrated Services for Web Applications
Integrated Services for Web ApplicationsIntegrated Services for Web Applications
Integrated Services for Web Applications
Saltmarch Media
 
Gaelyk - Web Apps In Practically No Time
Gaelyk - Web Apps In Practically No TimeGaelyk - Web Apps In Practically No Time
Gaelyk - Web Apps In Practically No Time
Saltmarch Media
 
CDI and Seam 3: an Exciting New Landscape for Java EE Development
CDI and Seam 3: an Exciting New Landscape for Java EE DevelopmentCDI and Seam 3: an Exciting New Landscape for Java EE Development
CDI and Seam 3: an Exciting New Landscape for Java EE Development
Saltmarch Media
 
JBoss at Work: Using JBoss AS 6
JBoss at Work: Using JBoss AS 6JBoss at Work: Using JBoss AS 6
JBoss at Work: Using JBoss AS 6
Saltmarch Media
 
WF and WCF with AppFabric – Application Infrastructure for OnPremise Services
WF and WCF with AppFabric – Application Infrastructure for OnPremise ServicesWF and WCF with AppFabric – Application Infrastructure for OnPremise Services
WF and WCF with AppFabric – Application Infrastructure for OnPremise Services
Saltmarch Media
 
“What did I do?” - T-SQL Worst Practices
“What did I do?” - T-SQL Worst Practices“What did I do?” - T-SQL Worst Practices
“What did I do?” - T-SQL Worst Practices
Saltmarch Media
 
Building Facebook Applications on Windows Azure
Building Facebook Applications on Windows AzureBuilding Facebook Applications on Windows Azure
Building Facebook Applications on Windows Azure
Saltmarch Media
 
Architecting Smarter Apps with Entity Framework
Architecting Smarter Apps with Entity FrameworkArchitecting Smarter Apps with Entity Framework
Architecting Smarter Apps with Entity Framework
Saltmarch Media
 
Agile Estimation
Agile EstimationAgile Estimation
Agile Estimation
Saltmarch Media
 
Alternate JVM Languages
Alternate JVM LanguagesAlternate JVM Languages
Alternate JVM Languages
Saltmarch Media
 
A Cocktail of Guice and Seam, the missing ingredients for Java EE 6
A Cocktail of Guice and Seam, the missing ingredients for Java EE 6A Cocktail of Guice and Seam, the missing ingredients for Java EE 6
A Cocktail of Guice and Seam, the missing ingredients for Java EE 6
Saltmarch Media
 
A Bit of Design Thinking for Developers
A Bit of Design Thinking for DevelopersA Bit of Design Thinking for Developers
A Bit of Design Thinking for Developers
Saltmarch Media
 

More from Saltmarch Media (18)

Concocting an MVC, Data Services and Entity Framework solution for Azure
Concocting an MVC, Data Services and Entity Framework solution for AzureConcocting an MVC, Data Services and Entity Framework solution for Azure
Concocting an MVC, Data Services and Entity Framework solution for Azure
 
Caring about Code Quality
Caring about Code QualityCaring about Code Quality
Caring about Code Quality
 
Learning Open Source Business Intelligence
Learning Open Source Business IntelligenceLearning Open Source Business Intelligence
Learning Open Source Business Intelligence
 
Java EE 7: the Voyage of the Cloud Treader
Java EE 7: the Voyage of the Cloud TreaderJava EE 7: the Voyage of the Cloud Treader
Java EE 7: the Voyage of the Cloud Treader
 
Is NoSQL The Future of Data Storage?
Is NoSQL The Future of Data Storage?Is NoSQL The Future of Data Storage?
Is NoSQL The Future of Data Storage?
 
Introduction to WCF RIA Services for Silverlight 4 Developers
Introduction to WCF RIA Services for Silverlight 4 DevelopersIntroduction to WCF RIA Services for Silverlight 4 Developers
Introduction to WCF RIA Services for Silverlight 4 Developers
 
Integrated Services for Web Applications
Integrated Services for Web ApplicationsIntegrated Services for Web Applications
Integrated Services for Web Applications
 
Gaelyk - Web Apps In Practically No Time
Gaelyk - Web Apps In Practically No TimeGaelyk - Web Apps In Practically No Time
Gaelyk - Web Apps In Practically No Time
 
CDI and Seam 3: an Exciting New Landscape for Java EE Development
CDI and Seam 3: an Exciting New Landscape for Java EE DevelopmentCDI and Seam 3: an Exciting New Landscape for Java EE Development
CDI and Seam 3: an Exciting New Landscape for Java EE Development
 
JBoss at Work: Using JBoss AS 6
JBoss at Work: Using JBoss AS 6JBoss at Work: Using JBoss AS 6
JBoss at Work: Using JBoss AS 6
 
WF and WCF with AppFabric – Application Infrastructure for OnPremise Services
WF and WCF with AppFabric – Application Infrastructure for OnPremise ServicesWF and WCF with AppFabric – Application Infrastructure for OnPremise Services
WF and WCF with AppFabric – Application Infrastructure for OnPremise Services
 
“What did I do?” - T-SQL Worst Practices
“What did I do?” - T-SQL Worst Practices“What did I do?” - T-SQL Worst Practices
“What did I do?” - T-SQL Worst Practices
 
Building Facebook Applications on Windows Azure
Building Facebook Applications on Windows AzureBuilding Facebook Applications on Windows Azure
Building Facebook Applications on Windows Azure
 
Architecting Smarter Apps with Entity Framework
Architecting Smarter Apps with Entity FrameworkArchitecting Smarter Apps with Entity Framework
Architecting Smarter Apps with Entity Framework
 
Agile Estimation
Agile EstimationAgile Estimation
Agile Estimation
 
Alternate JVM Languages
Alternate JVM LanguagesAlternate JVM Languages
Alternate JVM Languages
 
A Cocktail of Guice and Seam, the missing ingredients for Java EE 6
A Cocktail of Guice and Seam, the missing ingredients for Java EE 6A Cocktail of Guice and Seam, the missing ingredients for Java EE 6
A Cocktail of Guice and Seam, the missing ingredients for Java EE 6
 
A Bit of Design Thinking for Developers
A Bit of Design Thinking for DevelopersA Bit of Design Thinking for Developers
A Bit of Design Thinking for Developers
 

Recently uploaded

GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
UiPathCommunity
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.
ViralQR
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 

Recently uploaded (20)

GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 

Building RESTful Services with WCF 4.0

  • 1. Building RESTful Services with WCF Aaron Skonnard Cofounder, Pluralsight
  • 4. Why REST? 1. Most folks don't need SOAP's key features Transport-neutrality Advanced WS-* protocols Basic SOAP is just like REST but w/out the benefits
  • 5. Why REST? 2. REST is simple and the interface is uniform It's just HTTP + XML/JSON/XHTML Uniform interface that everyone understands Therefore, it’s more interoperable!
  • 6. REST is not RPC SOAP emphasizes verbs while REST emphasizes nouns or "resources" SOAP REST With REST, you define resources, getUser() and use a uniform interface to addUser() User { } operate on them (HTTP verbs) removeUser() Location { } ... getLocation() XML representation addLocation() ... <user> <name>Jane User</name> With SOAP, you define <gender>female</gender> custom operations (new <location href="http://example.org/locations/us/ny/nyc" >New York City, NY, US</location> verbs), tunnels through </user> POST
  • 7. Is REST too simple for complex systems?
  • 8. Why REST? 3. REST is how the Web works It scales from HTTP's built-in caching mechanisms Caching, bookmarking, navigating/links, SSL, etc You can access most REST services with a browser
  • 10. Windows Communication Foundation WCF doesn't take sides – it provides a unified programming model And allows you to use SOAP, POX, REST, whatever data format, etc Architecture: SOAP, REST, distributed objects, etc Transport Protocol: HTTP, TCP, MSMQ, etc WCF Message format: XML, RSS, JSON, binary, etc Message protocols: WS-*, none, etc
  • 11. WCF programming styles Most of the built-in WCF bindings use SOAP & WS-* by default You have to configure them to disable SOAP WCF 3.5 comes with a new Web (REST) programming model Found in System.ServiceModel.Web.dll Allows you to map HTTP requests to methods via URI templates You enable the Web model with a new binding/behavior Apply to messaging layer using WebHttpBinding Apply to dispatcher using WebHttpBehavior
  • 12. WebServiceHost WebServiceHost simplifes hosting Web-based services Derives from ServiceHost and overrides OnOpening Automatically adds endpoint for the base address using WebHttpBinding Automatically adds WebHttpBehavior to the endpoint ... this host WebServiceHost host = new WebServiceHost( adds the typeof(EvalService), Web binding new Uri("http://localhost:8080/evals")); & behavior host.Open(); // service is up and running Console.ReadLine(); // hold process open ... <%@ ServiceHost Language="C#" Service="EvalService" Factory= "System.ServiceModel.Activation.WebScriptServiceFactory" %>
  • 13. WebGetAttribute WebGetAttribute maps HTTP GET requests to a WCF method Supply a UriTemplate to defining URI mapping The UriTemplate variables map to method parameters by name BodyStyle property controls bare vs. wrapped Request/ResponseFormat control body format URI template [ServiceContract] public interface IEvalService { [WebGet(UriTemplate="evals?name={name}&score={score}")] [OperationContract] List<Eval> GetEvals(string name, int score); ...
  • 14. WebInvokeAttribute WebInvokeAttribute maps all other HTTP verbs to WCF methods Adds a Method property for specifying the verb (default is POST) Allows mapping UriTemplate variables Specify which Body is deserialized into remaining parameter HTTP verb this responds to [ServiceContract] public interface IEvals { [WebInvoke(UriTemplate ="/evals?name={name}",Method="PUT")] [OperationContract] void SubmitEval(string name, Eval eval /* body */); ...
  • 15. WebOperationContext Use WebOperationContext to access HTTP specifics within methods To retreived the current context use WebOperationContext.Current Provides properties for incoming/outgoing request/response context Each context object surfaces most common HTTP details URI, ContentLength, ContentType, Headers, ETag, etc
  • 16. WebMessageFormat WCF provides support for two primary Web formats: XML & JSON You control the format via RequestFormat and ResponseFormat [ServiceContract] public interface IEvals { [WebGet(UriTemplate = "/evals?name={nameFilter}", ResponseFormat = WebMessageFormat.Json)] [OperationContract] List<Eval> GetCurrentEvals(string nameFilter); ... Specify the message format
  • 17. Syndication programming model WCF comes with a simplified syndication programming model The logical data model for a feed is SyndicationFeed You can use it to produce/consume feeds in a variety of formats You use a SyndicationFeedFormatter to work with a specific format Use Atom10FeedFormatter or RSS20FeedFormatter today [ServiceKnownType(typeof(Atom10FeedFormatter))] [ServiceKnownType(typeof(Rss20FeedFormatter))] [ServiceContract] public interface IEvalService { [WebGet(UriTemplate = "evalsfeed")] [OperationContract] allows you to return SyndicationFeedFormatter GetEvalsFeed(); an Atom or RSS feed ... }
  • 19. Improved REST Support Many features in the WCF REST Starter Kit are now part of WCF 4.0
  • 20. Automatic help page WCF 4 provides an automatic help page for REST services Configure the <webHttp> behavior with helpEnabled=“true”
  • 21. Message format selection WCF 4 also provides automatic format selection for XML/JSON This feature is built on the HTTP “Accept” headers <configuration> <system.serviceModel> <standardEndpoints> <webHttpEndpoint> <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/> </webHttpEndpoint> </standardEndpoints> </system.serviceModel> </configuration>
  • 22. Http caching support WCF 4 provides a simpler model for managing HTTP caching They built on the ASP.NET caching profile architecture You define an [AspNetCacheProfile] for your GET operations Shields you from dealing with HTTP caching headers yourself [AspNetCacheProfile("CacheFor60Seconds")] [WebGet(UriTemplate=XmlItemTemplate)] [OperationContract] public Counter GetItemInXml() { return HandleGet(); }
  • 23. REST project templates Download the new REST project templates via the new Visual Studio 2010 Extension Manager (Tools | Extension Manager)
  • 25. WCF Web Api Futures http://wcf.codeplex.com