SlideShare a Scribd company logo
Enjoying the Move
from WCF to the
ASP.NET Web API
W. Kevin Hazzard
An API should be…
• Discoverable
• Intuitive
• Standards-based
• Economical
• Adaptive
• Fun
Enjoying the Move from WCF to the Web API
Enjoying the Move from WCF to the Web API
Enjoying the Move from WCF to the Web API
Richardson Maturity Model
martinfowler.com/articles/richardsonMaturityModel.html
The ASMX Experience
• Simple publication model
• HTTP for transport only
• Slow serialization
• Tightly integration with
ASP.NET and IIS
• Difficult to test
• Encourages the RPC
(swamp of POX) model
• A simple, Level 0
experience
Level 3
Level 2
Level 1
Level 0
The WCF Experience
• Complex publication model
• Highly configurable transports
• Better serialization
• Well-integrated with IIS
• Also easy to self-host
• Very rich metadata
• Difficult to test
• Rich data contracts hint at
resource-orientation
• A highly-adaptable but
complex Level 1 experience
Level 3
Level 2
Level 1
Level 0
From StackOverflow.com
“I am totally confused between WCF and
ASMX web services. I have used a lot of web
services in my earlier stage and now there is
this new thing introduced called WCF. I can
still create WCF that function as a web
service. I think there will be more stuff in
WCF. Can anyone provide me any article or
difference between WCF and Web services
such as which one to use and when?”
Result: many developers stayed with ASMX.
Cessna 172 v. Boeing 747
ASMX WCF
Enjoying the Move from WCF to the Web API
The Web API Experience
• Tightly coupled to HTTP
• Content negotiation
• Open-ended formatting
• No reliance on a platform
• (Almost) no metadata
• Solid resource-orientation
• Easy to test
• A simple, HTTP-
centric, Level 2 experience
with nascent hypermedia
support
Level 3
Level 2
Level 1
Level 0
H A T E O A S
Hypermedia As
The Engine Of
Application State
H A T E O A S
Today, would you design a
web application that requires
proprietary or native, third-
party plug-ins
to run inside the
web browser?
Web API Architecture
Web API Processing Architecture
HttpRequestMessage
HttpResponseMessag
e
HTTP Request
GET /index.html HTTP/1.1
Accept: text/html
Accept-Encoding: gzip, deflate
Accept-Language: en-US
User-Agent: Mozilla/5.0
Connection: Keep-Alive
HttpRequestMessage
Method
Headers
Content
GET /index.html HTTP/1.1
Accept: text/html
Accept-Encoding: gzip, deflate
Accept-Language: en-US
User-Agent: Mozilla/5.0
Connection: Keep-Alive
RequestUri
Extensions, etc.
• CreateErrorResponse – many overloads
• CreateResponse – many overloads
• GetClientCertificate
• GetProperty<T>
• GetQueryNameValuePairs
• GetUrlHelper
• Properties
Most are in System.Net.Http.dll.
HTTP Response
HTTP/1.1 200 OK
Cache-Control: private, max-age=0
Content-Type: application/json
Vary: Accept-Encoding
Date: Thu, 31 Dec 2015 23:59:59 GMT
Content-Length: 412
Connection: keep-alive
Set-Cookie: XYZ=123; domain=.me.com; path=/
[{"id" : 811, "First" : “Kevin”, ...
HttpResponseMessage
Headers
Content
HTTP/1.1 200 OK
Cache-Control: private, max-age=0
Content-Type: application/json
Vary: Accept-Encoding
Date: Thu, 31 Dec 2015 23:59:59 GMT
Content-Length: 412
Connection: keep-alive
Set-Cookie: XYZ=123; domain=.me.com; path=/
[{"id" : 811, "First" : “Kevin”, ...
StatusCode
Response Extras
• ReasonString – string
• IsSuccessStatusCode - bool
• RequestMessage – HttpRequestMessage
Important Attributes
o HttpGet
o HttpPost
o HttpPut
o HttpPatch
o HttpDelete
o HttpHead
o HttpOptions
o AcceptVerbs
o Authorize
o AllowAnonymous
o NonAction
o FromBody
o FromUri
o Queryable
Example One
Create a Simple Controller to Fetch Person Entities
Add OData Query Syntax Support
Constrain the Queryable Interface
Example One Summary
• Implement a basic controller with actions
• Demonstrate controller selection by convention
• Discuss controller selection by attribution
• Implement OData query parameters and
demonstrate
• Discuss Queryable attribute
Where’s my metadata?
• Web API publishes metadata!
• See Yao’s blog:
http://blogs.msdn.com/b/yaohuang1
• IApiExplorer research has yielded
o Web API Help Pages
o Web API Test Client
Example Two
Add WebApiTestClient to the Project and Configure
Turn Documentation Comments on and Configure
Cross-Cutting Concerns
HttpMessageHandler class:
protected abstract
Task<HttpResponseMessage>
SendAsync(
HttpRequestMessage request,
CancellationToken token);
DelegatingHandler
Derives from
HttpMessageHandler
Chains handlers together
in the order you
add them
Chained Handlers
Server
SendAsync SendAsync SendAsync
Example Three
Implement an Authorization Key Handler
Example Three Summary
• Implement an application key handler
• Discuss the invocation of the InnerHandler
• Demonstrate the creation and return of an error
response
• Discuss why throwing exceptions will always return
an HTTP 500 (Internal Server Error) result
• Demonstrate using the request object to create the
error response instead
• Attach the handler to the pipeline
• Debug with Help & Test
Enjoying the Move from WCF to the Web API
Security Tips
• Tunnel via SSL when possible
• Use Thinktecture IdentityModel for authentication
• Use [Authorize] and [AllowAnonymous] for
authentication
• For CORS support:
o ThinkTecture.IdentityModel
o Microsoft ASP.NET Web API Cross-Origin Support (Beta)
• Think PAINT
Self-Hosting
Microsoft ASP.NET Web API Self Host
http://topshelf-project.com
http://owin.org
https://katanaproject.codeplex.com
Issues and Missing Stuff
Caching (Safety)
Idempotence
Transaction Enlistment
Concurrency and
Instancing
Message Encryption
One-way APIs
Recommendations
• Focus on documentation, media types and
hyperlinking
• Use help pages and the WebApiTestClient
• Define cross-cutting concerns and use message
handlers
• Consider the Katana Project and Open Web
Interface for .NET (OWIN) for self-hosting
• Use the ThinkTecture.Identity Model
• Make testing a central theme in your API
development because it’s so easy
Contacting Kevin
@KevinHazzard
blogs.captechconsulting.com
manning.com/hazzard
Ad

More Related Content

What's hot (20)

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
 
The ASP.NET Web API for Beginners
The ASP.NET Web API for BeginnersThe ASP.NET Web API for Beginners
The ASP.NET Web API for Beginners
Kevin Hazzard
 
Overview of Rest Service and ASP.NET WEB API
Overview of Rest Service and ASP.NET WEB APIOverview of Rest Service and ASP.NET WEB API
Overview of Rest Service and ASP.NET WEB API
Pankaj Bajaj
 
Intro to web services
Intro to web servicesIntro to web services
Intro to web services
Neil Ghosh
 
Introduction to SOAP
Introduction to SOAPIntroduction to SOAP
Introduction to SOAP
Safwan Hashmi
 
Simple Object Access Protocol (SOAP)
Simple Object Access Protocol (SOAP)Simple Object Access Protocol (SOAP)
Simple Object Access Protocol (SOAP)
Mehul Boricha
 
SOAP--Simple Object Access Protocol
SOAP--Simple Object Access ProtocolSOAP--Simple Object Access Protocol
SOAP--Simple Object Access Protocol
Masud Rahman
 
Overview of java web services
Overview of java web servicesOverview of java web services
Overview of java web services
Todd Benson (I.T. SPECIALIST and I.T. SECURITY)
 
Web Services (SOAP, WSDL, UDDI)
Web Services (SOAP, WSDL, UDDI)Web Services (SOAP, WSDL, UDDI)
Web Services (SOAP, WSDL, UDDI)
Peter R. Egli
 
Simple object access protocol(soap )
Simple object access protocol(soap )Simple object access protocol(soap )
Simple object access protocol(soap )
balamurugan.k Kalibalamurugan
 
Java web services
Java web servicesJava web services
Java web services
kumar gaurav
 
Web Services
Web ServicesWeb Services
Web Services
Krish
 
Soap web service
Soap web serviceSoap web service
Soap web service
NITT, KAMK
 
webservices overview
webservices overviewwebservices overview
webservices overview
elliando dias
 
Web service introduction
Web service introductionWeb service introduction
Web service introduction
Sagara Gunathunga
 
WebService-Java
WebService-JavaWebService-Java
WebService-Java
halwal
 
Web Service
Web ServiceWeb Service
Web Service
Ashwani kumar
 
SOAP:Simple Object Access Protocol -XML-RPC
SOAP:Simple Object Access Protocol-XML-RPCSOAP:Simple Object Access Protocol-XML-RPC
SOAP:Simple Object Access Protocol -XML-RPC
elliando dias
 
REST and ASP.NET Web API (Milan)
REST and ASP.NET Web API (Milan)REST and ASP.NET Web API (Milan)
REST and ASP.NET Web API (Milan)
Jef Claes
 
Web Server-Side Programming Techniques
Web Server-Side Programming TechniquesWeb Server-Side Programming Techniques
Web Server-Side Programming Techniques
guest8899ec02
 
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
 
The ASP.NET Web API for Beginners
The ASP.NET Web API for BeginnersThe ASP.NET Web API for Beginners
The ASP.NET Web API for Beginners
Kevin Hazzard
 
Overview of Rest Service and ASP.NET WEB API
Overview of Rest Service and ASP.NET WEB APIOverview of Rest Service and ASP.NET WEB API
Overview of Rest Service and ASP.NET WEB API
Pankaj Bajaj
 
Intro to web services
Intro to web servicesIntro to web services
Intro to web services
Neil Ghosh
 
Introduction to SOAP
Introduction to SOAPIntroduction to SOAP
Introduction to SOAP
Safwan Hashmi
 
Simple Object Access Protocol (SOAP)
Simple Object Access Protocol (SOAP)Simple Object Access Protocol (SOAP)
Simple Object Access Protocol (SOAP)
Mehul Boricha
 
SOAP--Simple Object Access Protocol
SOAP--Simple Object Access ProtocolSOAP--Simple Object Access Protocol
SOAP--Simple Object Access Protocol
Masud Rahman
 
Web Services (SOAP, WSDL, UDDI)
Web Services (SOAP, WSDL, UDDI)Web Services (SOAP, WSDL, UDDI)
Web Services (SOAP, WSDL, UDDI)
Peter R. Egli
 
Web Services
Web ServicesWeb Services
Web Services
Krish
 
Soap web service
Soap web serviceSoap web service
Soap web service
NITT, KAMK
 
webservices overview
webservices overviewwebservices overview
webservices overview
elliando dias
 
WebService-Java
WebService-JavaWebService-Java
WebService-Java
halwal
 
SOAP:Simple Object Access Protocol -XML-RPC
SOAP:Simple Object Access Protocol-XML-RPCSOAP:Simple Object Access Protocol-XML-RPC
SOAP:Simple Object Access Protocol -XML-RPC
elliando dias
 
REST and ASP.NET Web API (Milan)
REST and ASP.NET Web API (Milan)REST and ASP.NET Web API (Milan)
REST and ASP.NET Web API (Milan)
Jef Claes
 
Web Server-Side Programming Techniques
Web Server-Side Programming TechniquesWeb Server-Side Programming Techniques
Web Server-Side Programming Techniques
guest8899ec02
 

Similar to Enjoying the Move from WCF to the Web API (20)

ASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiASP.NET Mvc 4 web api
ASP.NET Mvc 4 web api
Tiago Knoch
 
Restful风格ž„web服务架构
Restful风格ž„web服务架构Restful风格ž„web服务架构
Restful风格ž„web服务架构
Benjamin Tan
 
Web api
Web apiWeb api
Web api
Sudhakar Sharma
 
ASP.NET WEB API Training
ASP.NET WEB API TrainingASP.NET WEB API Training
ASP.NET WEB API Training
Chalermpon Areepong
 
Windows 8 Metro apps and the outside world
Windows 8 Metro apps and the outside worldWindows 8 Metro apps and the outside world
Windows 8 Metro apps and the outside world
Prabhakaran Soundarapandian
 
JAVA Servlets
JAVA ServletsJAVA Servlets
JAVA Servlets
deepak kumar
 
WebSockets wiith Scala and Play! Framework
WebSockets wiith Scala and Play! FrameworkWebSockets wiith Scala and Play! Framework
WebSockets wiith Scala and Play! Framework
Fabio Tiriticco
 
Building Restful Applications Using Php
Building Restful Applications Using PhpBuilding Restful Applications Using Php
Building Restful Applications Using Php
Sudheer Satyanarayana
 
Using Communication and Messaging API in the HTML5 World
Using Communication and Messaging API in the HTML5 WorldUsing Communication and Messaging API in the HTML5 World
Using Communication and Messaging API in the HTML5 World
Gil Fink
 
Using REST with VSTS and TFS
Using REST with VSTS and TFSUsing REST with VSTS and TFS
Using REST with VSTS and TFS
Jeff Bramwell
 
Documenting REST APIs
Documenting REST APIsDocumenting REST APIs
Documenting REST APIs
Tom Johnson
 
Java Servlet Programming under Ubuntu Linux by Tushar B Kute
Java Servlet Programming under Ubuntu Linux by Tushar B KuteJava Servlet Programming under Ubuntu Linux by Tushar B Kute
Java Servlet Programming under Ubuntu Linux by Tushar B Kute
Tushar B Kute
 
Servlets api overview
Servlets api overviewServlets api overview
Servlets api overview
ramya marichamy
 
Using communication and messaging API in the HTML5 world - GIl Fink, sparXsys
Using communication and messaging API in the HTML5 world - GIl Fink, sparXsysUsing communication and messaging API in the HTML5 world - GIl Fink, sparXsys
Using communication and messaging API in the HTML5 world - GIl Fink, sparXsys
Codemotion Tel Aviv
 
Middleware in Asp.Net Core
Middleware in Asp.Net CoreMiddleware in Asp.Net Core
Middleware in Asp.Net Core
Shahriar Hossain
 
Matt Gauger - Lamp vs. the world - MKE PHP Users Group - December 14, 2010
Matt Gauger - Lamp vs. the world - MKE PHP Users Group - December 14, 2010 Matt Gauger - Lamp vs. the world - MKE PHP Users Group - December 14, 2010
Matt Gauger - Lamp vs. the world - MKE PHP Users Group - December 14, 2010
Matt Gauger
 
Session 26 - Servlets Part 2
Session 26 - Servlets Part 2Session 26 - Servlets Part 2
Session 26 - Servlets Part 2
PawanMM
 
web-servers3952 (1)qwjelkjqwlkjkqlwe.ppt
web-servers3952 (1)qwjelkjqwlkjkqlwe.pptweb-servers3952 (1)qwjelkjqwlkjkqlwe.ppt
web-servers3952 (1)qwjelkjqwlkjkqlwe.ppt
20521742
 
Servlets
ServletsServlets
Servlets
Sasidhar Kothuru
 
Wcf rest api introduction
Wcf rest api introductionWcf rest api introduction
Wcf rest api introduction
Himanshu Desai
 
ASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiASP.NET Mvc 4 web api
ASP.NET Mvc 4 web api
Tiago Knoch
 
Restful风格ž„web服务架构
Restful风格ž„web服务架构Restful风格ž„web服务架构
Restful风格ž„web服务架构
Benjamin Tan
 
WebSockets wiith Scala and Play! Framework
WebSockets wiith Scala and Play! FrameworkWebSockets wiith Scala and Play! Framework
WebSockets wiith Scala and Play! Framework
Fabio Tiriticco
 
Building Restful Applications Using Php
Building Restful Applications Using PhpBuilding Restful Applications Using Php
Building Restful Applications Using Php
Sudheer Satyanarayana
 
Using Communication and Messaging API in the HTML5 World
Using Communication and Messaging API in the HTML5 WorldUsing Communication and Messaging API in the HTML5 World
Using Communication and Messaging API in the HTML5 World
Gil Fink
 
Using REST with VSTS and TFS
Using REST with VSTS and TFSUsing REST with VSTS and TFS
Using REST with VSTS and TFS
Jeff Bramwell
 
Documenting REST APIs
Documenting REST APIsDocumenting REST APIs
Documenting REST APIs
Tom Johnson
 
Java Servlet Programming under Ubuntu Linux by Tushar B Kute
Java Servlet Programming under Ubuntu Linux by Tushar B KuteJava Servlet Programming under Ubuntu Linux by Tushar B Kute
Java Servlet Programming under Ubuntu Linux by Tushar B Kute
Tushar B Kute
 
Using communication and messaging API in the HTML5 world - GIl Fink, sparXsys
Using communication and messaging API in the HTML5 world - GIl Fink, sparXsysUsing communication and messaging API in the HTML5 world - GIl Fink, sparXsys
Using communication and messaging API in the HTML5 world - GIl Fink, sparXsys
Codemotion Tel Aviv
 
Middleware in Asp.Net Core
Middleware in Asp.Net CoreMiddleware in Asp.Net Core
Middleware in Asp.Net Core
Shahriar Hossain
 
Matt Gauger - Lamp vs. the world - MKE PHP Users Group - December 14, 2010
Matt Gauger - Lamp vs. the world - MKE PHP Users Group - December 14, 2010 Matt Gauger - Lamp vs. the world - MKE PHP Users Group - December 14, 2010
Matt Gauger - Lamp vs. the world - MKE PHP Users Group - December 14, 2010
Matt Gauger
 
Session 26 - Servlets Part 2
Session 26 - Servlets Part 2Session 26 - Servlets Part 2
Session 26 - Servlets Part 2
PawanMM
 
web-servers3952 (1)qwjelkjqwlkjkqlwe.ppt
web-servers3952 (1)qwjelkjqwlkjkqlwe.pptweb-servers3952 (1)qwjelkjqwlkjkqlwe.ppt
web-servers3952 (1)qwjelkjqwlkjkqlwe.ppt
20521742
 
Wcf rest api introduction
Wcf rest api introductionWcf rest api introduction
Wcf rest api introduction
Himanshu Desai
 
Ad

More from Kevin Hazzard (6)

C# 6 and 7 and Futures 20180607
C# 6 and 7 and Futures 20180607C# 6 and 7 and Futures 20180607
C# 6 and 7 and Futures 20180607
Kevin Hazzard
 
What the math geeks don't want you to know about F#
What the math geeks don't want you to know about F#What the math geeks don't want you to know about F#
What the math geeks don't want you to know about F#
Kevin Hazzard
 
Better contracts better code - august 2010
Better contracts   better code - august 2010Better contracts   better code - august 2010
Better contracts better code - august 2010
Kevin Hazzard
 
Introduction to SQL Azure
Introduction to SQL AzureIntroduction to SQL Azure
Introduction to SQL Azure
Kevin Hazzard
 
Enterprise Data Validation
Enterprise Data ValidationEnterprise Data Validation
Enterprise Data Validation
Kevin Hazzard
 
Dynamic Language Performance
Dynamic Language PerformanceDynamic Language Performance
Dynamic Language Performance
Kevin Hazzard
 
C# 6 and 7 and Futures 20180607
C# 6 and 7 and Futures 20180607C# 6 and 7 and Futures 20180607
C# 6 and 7 and Futures 20180607
Kevin Hazzard
 
What the math geeks don't want you to know about F#
What the math geeks don't want you to know about F#What the math geeks don't want you to know about F#
What the math geeks don't want you to know about F#
Kevin Hazzard
 
Better contracts better code - august 2010
Better contracts   better code - august 2010Better contracts   better code - august 2010
Better contracts better code - august 2010
Kevin Hazzard
 
Introduction to SQL Azure
Introduction to SQL AzureIntroduction to SQL Azure
Introduction to SQL Azure
Kevin Hazzard
 
Enterprise Data Validation
Enterprise Data ValidationEnterprise Data Validation
Enterprise Data Validation
Kevin Hazzard
 
Dynamic Language Performance
Dynamic Language PerformanceDynamic Language Performance
Dynamic Language Performance
Kevin Hazzard
 
Ad

Recently uploaded (20)

Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 

Enjoying the Move from WCF to the Web API

  • 1. Enjoying the Move from WCF to the ASP.NET Web API W. Kevin Hazzard
  • 2. An API should be… • Discoverable • Intuitive • Standards-based • Economical • Adaptive • Fun
  • 7. The ASMX Experience • Simple publication model • HTTP for transport only • Slow serialization • Tightly integration with ASP.NET and IIS • Difficult to test • Encourages the RPC (swamp of POX) model • A simple, Level 0 experience Level 3 Level 2 Level 1 Level 0
  • 8. The WCF Experience • Complex publication model • Highly configurable transports • Better serialization • Well-integrated with IIS • Also easy to self-host • Very rich metadata • Difficult to test • Rich data contracts hint at resource-orientation • A highly-adaptable but complex Level 1 experience Level 3 Level 2 Level 1 Level 0
  • 9. From StackOverflow.com “I am totally confused between WCF and ASMX web services. I have used a lot of web services in my earlier stage and now there is this new thing introduced called WCF. I can still create WCF that function as a web service. I think there will be more stuff in WCF. Can anyone provide me any article or difference between WCF and Web services such as which one to use and when?” Result: many developers stayed with ASMX.
  • 10. Cessna 172 v. Boeing 747 ASMX WCF
  • 12. The Web API Experience • Tightly coupled to HTTP • Content negotiation • Open-ended formatting • No reliance on a platform • (Almost) no metadata • Solid resource-orientation • Easy to test • A simple, HTTP- centric, Level 2 experience with nascent hypermedia support Level 3 Level 2 Level 1 Level 0
  • 13. H A T E O A S Hypermedia As The Engine Of Application State H A T E O A S
  • 14. Today, would you design a web application that requires proprietary or native, third- party plug-ins to run inside the web browser?
  • 16. Web API Processing Architecture HttpRequestMessage HttpResponseMessag e
  • 17. HTTP Request GET /index.html HTTP/1.1 Accept: text/html Accept-Encoding: gzip, deflate Accept-Language: en-US User-Agent: Mozilla/5.0 Connection: Keep-Alive
  • 18. HttpRequestMessage Method Headers Content GET /index.html HTTP/1.1 Accept: text/html Accept-Encoding: gzip, deflate Accept-Language: en-US User-Agent: Mozilla/5.0 Connection: Keep-Alive RequestUri
  • 19. Extensions, etc. • CreateErrorResponse – many overloads • CreateResponse – many overloads • GetClientCertificate • GetProperty<T> • GetQueryNameValuePairs • GetUrlHelper • Properties Most are in System.Net.Http.dll.
  • 20. HTTP Response HTTP/1.1 200 OK Cache-Control: private, max-age=0 Content-Type: application/json Vary: Accept-Encoding Date: Thu, 31 Dec 2015 23:59:59 GMT Content-Length: 412 Connection: keep-alive Set-Cookie: XYZ=123; domain=.me.com; path=/ [{"id" : 811, "First" : “Kevin”, ...
  • 21. HttpResponseMessage Headers Content HTTP/1.1 200 OK Cache-Control: private, max-age=0 Content-Type: application/json Vary: Accept-Encoding Date: Thu, 31 Dec 2015 23:59:59 GMT Content-Length: 412 Connection: keep-alive Set-Cookie: XYZ=123; domain=.me.com; path=/ [{"id" : 811, "First" : “Kevin”, ... StatusCode
  • 22. Response Extras • ReasonString – string • IsSuccessStatusCode - bool • RequestMessage – HttpRequestMessage
  • 23. Important Attributes o HttpGet o HttpPost o HttpPut o HttpPatch o HttpDelete o HttpHead o HttpOptions o AcceptVerbs o Authorize o AllowAnonymous o NonAction o FromBody o FromUri o Queryable
  • 24. Example One Create a Simple Controller to Fetch Person Entities Add OData Query Syntax Support Constrain the Queryable Interface
  • 25. Example One Summary • Implement a basic controller with actions • Demonstrate controller selection by convention • Discuss controller selection by attribution • Implement OData query parameters and demonstrate • Discuss Queryable attribute
  • 26. Where’s my metadata? • Web API publishes metadata! • See Yao’s blog: http://blogs.msdn.com/b/yaohuang1 • IApiExplorer research has yielded o Web API Help Pages o Web API Test Client
  • 27. Example Two Add WebApiTestClient to the Project and Configure Turn Documentation Comments on and Configure
  • 28. Cross-Cutting Concerns HttpMessageHandler class: protected abstract Task<HttpResponseMessage> SendAsync( HttpRequestMessage request, CancellationToken token);
  • 31. Example Three Implement an Authorization Key Handler
  • 32. Example Three Summary • Implement an application key handler • Discuss the invocation of the InnerHandler • Demonstrate the creation and return of an error response • Discuss why throwing exceptions will always return an HTTP 500 (Internal Server Error) result • Demonstrate using the request object to create the error response instead • Attach the handler to the pipeline • Debug with Help & Test
  • 34. Security Tips • Tunnel via SSL when possible • Use Thinktecture IdentityModel for authentication • Use [Authorize] and [AllowAnonymous] for authentication • For CORS support: o ThinkTecture.IdentityModel o Microsoft ASP.NET Web API Cross-Origin Support (Beta) • Think PAINT
  • 35. Self-Hosting Microsoft ASP.NET Web API Self Host http://topshelf-project.com http://owin.org https://katanaproject.codeplex.com
  • 36. Issues and Missing Stuff Caching (Safety) Idempotence Transaction Enlistment Concurrency and Instancing Message Encryption One-way APIs
  • 37. Recommendations • Focus on documentation, media types and hyperlinking • Use help pages and the WebApiTestClient • Define cross-cutting concerns and use message handlers • Consider the Katana Project and Open Web Interface for .NET (OWIN) for self-hosting • Use the ThinkTecture.Identity Model • Make testing a central theme in your API development because it’s so easy

Editor's Notes

  • #14: Values idealism over pragmatism and app longevity over short-term efficiencyResult: nobody does it correctly