SlideShare una empresa de Scribd logo
1 de 38
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
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
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
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

Más contenido relacionado

La actualidad más candente

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 & SOAPUIAdvancio
 
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 BeginnersKevin 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 APIPankaj Bajaj
 
Intro to web services
Intro to web servicesIntro to web services
Intro to web servicesNeil Ghosh
 
Introduction to SOAP
Introduction to SOAPIntroduction to SOAP
Introduction to SOAPSafwan 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 ProtocolMasud 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 ServicesKrish
 
Soap web service
Soap web serviceSoap web service
Soap web serviceNITT, KAMK
 
webservices overview
webservices overviewwebservices overview
webservices overviewelliando dias
 
WebService-Java
WebService-JavaWebService-Java
WebService-Javahalwal
 
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-RPCelliando 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 Techniquesguest8899ec02
 

La actualidad más candente (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
 
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
 
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
 
Intro to web services
Intro to web servicesIntro to web services
Intro to web services
 
Introduction to SOAP
Introduction to SOAPIntroduction to SOAP
Introduction to SOAP
 
Simple Object Access Protocol (SOAP)
Simple Object Access Protocol (SOAP)Simple Object Access Protocol (SOAP)
Simple Object Access Protocol (SOAP)
 
SOAP--Simple Object Access Protocol
SOAP--Simple Object Access ProtocolSOAP--Simple Object Access Protocol
SOAP--Simple Object Access Protocol
 
Overview of java web services
Overview of java web servicesOverview of java web services
Overview of java web services
 
Web Services (SOAP, WSDL, UDDI)
Web Services (SOAP, WSDL, UDDI)Web Services (SOAP, WSDL, UDDI)
Web Services (SOAP, WSDL, UDDI)
 
Simple object access protocol(soap )
Simple object access protocol(soap )Simple object access protocol(soap )
Simple object access protocol(soap )
 
Java web services
Java web servicesJava web services
Java web services
 
Web Services
Web ServicesWeb Services
Web Services
 
Soap web service
Soap web serviceSoap web service
Soap web service
 
webservices overview
webservices overviewwebservices overview
webservices overview
 
Web service introduction
Web service introductionWeb service introduction
Web service introduction
 
WebService-Java
WebService-JavaWebService-Java
WebService-Java
 
Web Service
Web ServiceWeb Service
Web Service
 
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
 
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)
 
Web Server-Side Programming Techniques
Web Server-Side Programming TechniquesWeb Server-Side Programming Techniques
Web Server-Side Programming Techniques
 

Similar a Enjoying the Move from WCF to the Web API

ASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiTiago 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! FrameworkFabio Tiriticco
 
Building Restful Applications Using Php
Building Restful Applications Using PhpBuilding Restful Applications Using Php
Building Restful Applications Using PhpSudheer 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 WorldGil Fink
 
Using REST with VSTS and TFS
Using REST with VSTS and TFSUsing REST with VSTS and TFS
Using REST with VSTS and TFSJeff Bramwell
 
Documenting REST APIs
Documenting REST APIsDocumenting REST APIs
Documenting REST APIsTom 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 KuteTushar 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, sparXsysCodemotion Tel Aviv
 
Middleware in Asp.Net Core
Middleware in Asp.Net CoreMiddleware in Asp.Net Core
Middleware in Asp.Net CoreShahriar 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 2PawanMM
 
web-servers3952 (1)qwjelkjqwlkjkqlwe.ppt
web-servers3952 (1)qwjelkjqwlkjkqlwe.pptweb-servers3952 (1)qwjelkjqwlkjkqlwe.ppt
web-servers3952 (1)qwjelkjqwlkjkqlwe.ppt20521742
 
Wcf rest api introduction
Wcf rest api introductionWcf rest api introduction
Wcf rest api introductionHimanshu Desai
 

Similar a 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
 
Restful风格ž„web服务架构
Restful风格ž„web服务架构Restful风格ž„web服务架构
Restful风格ž„web服务架构
 
Web api
Web apiWeb api
Web api
 
ASP.NET WEB API Training
ASP.NET WEB API TrainingASP.NET WEB API Training
ASP.NET WEB API Training
 
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
 
JAVA Servlets
JAVA ServletsJAVA Servlets
JAVA Servlets
 
WebSockets wiith Scala and Play! Framework
WebSockets wiith Scala and Play! FrameworkWebSockets wiith Scala and Play! Framework
WebSockets wiith Scala and Play! Framework
 
Building Restful Applications Using Php
Building Restful Applications Using PhpBuilding Restful Applications Using Php
Building Restful Applications Using Php
 
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
 
Using REST with VSTS and TFS
Using REST with VSTS and TFSUsing REST with VSTS and TFS
Using REST with VSTS and TFS
 
Documenting REST APIs
Documenting REST APIsDocumenting REST APIs
Documenting REST APIs
 
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
 
Servlets api overview
Servlets api overviewServlets api overview
Servlets api overview
 
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
 
Middleware in Asp.Net Core
Middleware in Asp.Net CoreMiddleware in Asp.Net Core
Middleware in Asp.Net Core
 
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
 
Session 26 - Servlets Part 2
Session 26 - Servlets Part 2Session 26 - Servlets Part 2
Session 26 - Servlets Part 2
 
web-servers3952 (1)qwjelkjqwlkjkqlwe.ppt
web-servers3952 (1)qwjelkjqwlkjkqlwe.pptweb-servers3952 (1)qwjelkjqwlkjkqlwe.ppt
web-servers3952 (1)qwjelkjqwlkjkqlwe.ppt
 
Servlets
ServletsServlets
Servlets
 
Wcf rest api introduction
Wcf rest api introductionWcf rest api introduction
Wcf rest api introduction
 

Más de 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 20180607Kevin 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 2010Kevin Hazzard
 
Introduction to SQL Azure
Introduction to SQL AzureIntroduction to SQL Azure
Introduction to SQL AzureKevin Hazzard
 
Enterprise Data Validation
Enterprise Data ValidationEnterprise Data Validation
Enterprise Data ValidationKevin Hazzard
 
Dynamic Language Performance
Dynamic Language PerformanceDynamic Language Performance
Dynamic Language PerformanceKevin Hazzard
 

Más de 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
 
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#
 
Better contracts better code - august 2010
Better contracts   better code - august 2010Better contracts   better code - august 2010
Better contracts better code - august 2010
 
Introduction to SQL Azure
Introduction to SQL AzureIntroduction to SQL Azure
Introduction to SQL Azure
 
Enterprise Data Validation
Enterprise Data ValidationEnterprise Data Validation
Enterprise Data Validation
 
Dynamic Language Performance
Dynamic Language PerformanceDynamic Language Performance
Dynamic Language Performance
 

Último

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 

Último (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 

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
  • 3.
  • 4.
  • 5.
  • 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
  • 11.
  • 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
  • 33.
  • 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

Notas del editor

  1. Values idealism over pragmatism and app longevity over short-term efficiencyResult: nobody does it correctly