SlideShare a Scribd company logo
輕鬆上手
ASP.NET Web API 2.1.2
陳傳興(Bruce)
bruce.mvc@outlook.com
簡介
▪ 2012~2014年,連任三屆微軟最有價值專家(MVP)
▪ 微軟 TechDays & MSDN講座 講師
▪ 台中市電腦商業同業公會 特約講師
▪ 中國生產力中心(CPC) 特約講師
▪ Global Windows Azure Bootcamp 2014 TW 講師
▪ Study4.TW 成員及講師 (http://study4.tw)
▪ twMVC 核心成員及講師 (http://mvc.tw)
▪ 著作
– 《ASP.NET MVC4 網站開發美學》
– 《ASP.NET MVC ? 網站開發美學》
2
今天不講ASP.NET Web API
▪ 請購買《ASP.NET MVC4網站開發美學》
3
今天不講ASP.NET Web API 2
▪ TechDays Taiwan 2013 Dev303
– http://mvc.tw/001g
▪ Web Services 開發實戰: 使用 ASP.NET Web API 2
– http://mvc.tw/001h
4
今日主軸
5
Web API
Tools2.1.2
ASP.NET Web API 2.1.2
▪ Global Error Handling
▪ Attribute routing improvements
▪ Help Page improvements
▪ IgnoreRoute support
▪ BSON media-type formatter
▪ Better support for async filters
▪ Query Parsing for the client formatting library
6
語意化版本
▪ http://semver.org/lang/zh-TW/
▪ 所有NuGet套件未來都會循著Semantic Versioning規格。
▪ ASP.NET MVC 5.1 RTM
ASP.NET Web API 2.1 RTM
版本號是"5.1.1"。
▪ ASP.NET Web API 2.1.2 版本號是"5.1.2"
7
Update 2
▪ Visual Studio 2013 Update 2
▪ MVC / Web API範本有更新
預設載入
ASP.NET MVC 5.1.2
ASP.NET Web API 2.1.2(5.1.2)
8
我不想裝 Update 2
▪ Visual Studio 2013 Update 1
▪ VS 2013 with ASP.NET and Web Tools 2013.1
http://www.asp.net/downloads
▪ PM> Update-Package Microsoft.AspNet.WebApi
9
如果你端午節很無聊的話
▪ PM> Install-Package Microsoft.AspNet.WebApi -Pre
– ASP.NET Web API 2.2 RC(5.2.0-rc)
Entity Framework 6.1
Tool
Entity Framework 6.1
▪ Entity Framework 6.1.0 Tools for Visual Studio 2012 & 2013
▪ http://mvc.tw/001e
12
來自星星資料庫的Code First
13
Web API Tracing
Web API Tracing
開發時的好幫手
▪ Install-Package Microsoft.AspNet.WebApi.Tracing
▪ Update-Package Microsoft.AspNet.WebApi.WebHost
▪ config.EnableSystemDiagnosticsTracing();
15
全域錯誤處理常式
Feature
Global Error Handling
▪ 所有未處理的例外現在可以通過一個中央機制來記錄,並且未處
理例外的行為可以客製化。
▪ ExceptionLogger
表示未處理的例外狀況記錄器。
▪ ExceptionHandler
表示未處理的例外狀況處理常式。
▪ System.Web.Http.ExceptionHandling命名空間
17
elmah.io
Tool
elmah.io
屬性路由改善
Feature
Attribute routing improvements
▪ 屬性路由(Attribute routing)由Web API 2提供。在Web API
2.1支援條件限制(constraint),版本控制與基於header的路由
選擇。
▪ 提供IDirectRouteFactory與RouteFactoryAttribute來客製化路
由。
▪ 提供IRoutePrefix與RoutePrefixAttribute來擴充路由字首。
21
Help Page
Feature
Help Page improvements
▪ 在說明文件中獨立呈顯Action方法的參數或回傳型別。
▪ 在說明文件中呈現資料模型註解。
▪ UI設計更新。
23
WebApiTestClient
Tool
WebApiTestClient
▪ Install-Package WebApiTestClient
api.cshtml
▪ @*~AreasHelpPageViewsHelpApi.cshtml*@
▪ @Html.DisplayForModel("TestClientDialogs")
▪ @section scripts
▪ {
▪ @Html.DisplayForModel("TestClientReferences")
▪ }
忽略路由
Feature
IgnoreRoute support
▪ ASP.NET Web API 2.1支援IgnoreRoute的URL模式,只需要透過
HttpRouteCollection的IgnoreRoute擴充方法。
28
BSON
Feature
BSON media-type formatter
▪ http://bsonspec.org/
▪ BSON [bee · sahn]
▪ 二進位JSON。
▪ 目前主要使用在MangoDB。
▪ Tool:bsondump,http://mvc.tw/001f。
30
Async Filters
Feature
Better support for async filters
▪ AuthorizationFilterAttribute
– OnAuthorization
– OnAuthorizationAsync
▪ ActionFilterAttribute
– OnActionExecuting
– OnActionExecuted
– OnActionExecutingAsync
– OnActionExecutedAsync
▪ ExceptionFilterAttribute
– OnException
– OnExceptionAsync
32
查詢字串
Feature
Query Parsing
▪ Web API Client Library可攜式版本援Qurey String的解析與建立。
34
批次處理
for Web API 2
ASP.NET Web API Batching
▪ ASP.NET Web API 2提供。
▪ Batch poing
– HTTP批次端點
▪ 透過MapHttpBatchRoute設定HTTP批次端點,提供HTTP處理批次要求的能力。
– OData批次端點
▪ 透過MapODataRoute設定OData Service批次端點,提供OData Service處理批
次要求的能力。
36
郵差先生
Tool
變變變
OAuth登入
for Web API 2
Extenal Login
▪ ASP.NET Web API 2提供。
▪ Web API 2內建OAuth Authorization Server,提供Token方式
來進行會員管理的功能。
▪ 可整合第三方OAuth 2.0服務,目前內建整合Microsoft Account、
Twitter、Facebook、Google提供的Token進行驗證使用者作業。
40
罵完了,還是要工商服務 :D
▪ WEB SERVICES開發實戰班:使用ASP.NET WEB API 2-台中班
▪ http://goo.gl/TZ4jHo
Blog與Web
▪ Blog:http://blog.kkbruce.tw
▪ Web:http://kkbruce.tw
參考
▪ http://www.asp.net/web-api
▪ https://aspnetwebstack.codeplex.com/
▪ http://www.odata.org/documentation/odata-version-3-
0/batch-processing/
▪ http://oauth.net/2/
43
謝謝各位
• 本投影片所包含的商標與文字皆屬原著作者所有。
• 本著作係採用姓名標示-非商業性-相同方式分享 3.0 台灣授權。閱讀本授權條款,請到
http://creativecommons.org/licenses/by-nc-sa/3.0/tw/,或寫信至Creative Commons, 444 Castro
Street, Suite 900, Mountain View, California, 94041, USA.
Ad

Recommended

輕鬆上手ASP.NET Web API 2.1.2
輕鬆上手ASP.NET Web API 2.1.2
Bruce Chen
 
一小時可以打造什麼服務Plus twMVC#18
一小時可以打造什麼服務Plus twMVC#18
twMVC
 
輕鬆上手Asp.net web api 2.1-twMVC#14
輕鬆上手Asp.net web api 2.1-twMVC#14
twMVC
 
KSDG-ASP.NET MVC 5 Overview (偽三國誌)
KSDG-ASP.NET MVC 5 Overview (偽三國誌)
Bruce Chen
 
twMVC#42 讓我們用一種方式來開發吧
twMVC#42 讓我們用一種方式來開發吧
twMVC
 
twMVC#31網站上線了然後呢
twMVC#31網站上線了然後呢
twMVC
 
動手打造 application framework-twMVC#15
動手打造 application framework-twMVC#15
twMVC
 
twMVC#43 Visual Studio 2022 新功能拆解
twMVC#43 Visual Studio 2022 新功能拆解
twMVC
 
twMVC#33聊聊如何自建 Facebook {廣告} 服務 with API
twMVC#33聊聊如何自建 Facebook {廣告} 服務 with API
twMVC
 
開發的效能與效率-twMVC#15
開發的效能與效率-twMVC#15
twMVC
 
前端工程師與室內裝修師傅的相似之處-twMVC#16
前端工程師與室內裝修師傅的相似之處-twMVC#16
twMVC
 
twMVC#29 -Learning Machine Learning with Movie Recommendation
twMVC#29 -Learning Machine Learning with Movie Recommendation
Mia Chang
 
Asp.net mvc 從無到有 -twMVC#2
Asp.net mvc 從無到有 -twMVC#2
twMVC
 
MVC實戰分享 分頁與排序相關技巧-tw mvc#13
MVC實戰分享 分頁與排序相關技巧-tw mvc#13
twMVC
 
Angular js入门分享 by 王栋
Angular js入门分享 by 王栋
栋 王
 
twMVC#41 The journey of source generator
twMVC#41 The journey of source generator
twMVC
 
ASP.NET MVC 善用網路資源快速完打造網站
ASP.NET MVC 善用網路資源快速完打造網站
twMVC
 
Mark_Resource
Mark_Resource
ibtesting
 
twMVC#29 | 當.Net Core 遇到AWS Lambda
twMVC#29 | 當.Net Core 遇到AWS Lambda
twMVC
 
twMVC#21 | 你所不知道的 Visual Studio
twMVC#21 | 你所不知道的 Visual Studio
twMVC
 
Angular.js & ASP.NET in Study4
Angular.js & ASP.NET in Study4
Kyle Shen
 
SignalR實戰技巧 twmvc#17
SignalR實戰技巧 twmvc#17
twMVC
 
Vs2013新功能介紹 twMVC#11
Vs2013新功能介紹 twMVC#11
twMVC
 
twMVC#22 | 一個微信專案從0到.000的效能調教之路
twMVC#22 | 一個微信專案從0到.000的效能調教之路
twMVC
 
專案分層架構 twMVC#18
專案分層架構 twMVC#18
twMVC
 
twMVC#22 | 什麼鬼的IOC與DI
twMVC#22 | 什麼鬼的IOC與DI
twMVC
 
twMVC#28 | visual studio 2017 新功能介紹
twMVC#28 | visual studio 2017 新功能介紹
twMVC
 
twMVC#14 | 輕鬆上手ASP.NET Web API 2
twMVC#14 | 輕鬆上手ASP.NET Web API 2
twMVC
 
ASP.NET MVC Web API -twMVC#8
ASP.NET MVC Web API -twMVC#8
twMVC
 
twMVC#08 | Web API
twMVC#08 | Web API
twMVC
 

More Related Content

What's hot (19)

twMVC#33聊聊如何自建 Facebook {廣告} 服務 with API
twMVC#33聊聊如何自建 Facebook {廣告} 服務 with API
twMVC
 
開發的效能與效率-twMVC#15
開發的效能與效率-twMVC#15
twMVC
 
前端工程師與室內裝修師傅的相似之處-twMVC#16
前端工程師與室內裝修師傅的相似之處-twMVC#16
twMVC
 
twMVC#29 -Learning Machine Learning with Movie Recommendation
twMVC#29 -Learning Machine Learning with Movie Recommendation
Mia Chang
 
Asp.net mvc 從無到有 -twMVC#2
Asp.net mvc 從無到有 -twMVC#2
twMVC
 
MVC實戰分享 分頁與排序相關技巧-tw mvc#13
MVC實戰分享 分頁與排序相關技巧-tw mvc#13
twMVC
 
Angular js入门分享 by 王栋
Angular js入门分享 by 王栋
栋 王
 
twMVC#41 The journey of source generator
twMVC#41 The journey of source generator
twMVC
 
ASP.NET MVC 善用網路資源快速完打造網站
ASP.NET MVC 善用網路資源快速完打造網站
twMVC
 
Mark_Resource
Mark_Resource
ibtesting
 
twMVC#29 | 當.Net Core 遇到AWS Lambda
twMVC#29 | 當.Net Core 遇到AWS Lambda
twMVC
 
twMVC#21 | 你所不知道的 Visual Studio
twMVC#21 | 你所不知道的 Visual Studio
twMVC
 
Angular.js & ASP.NET in Study4
Angular.js & ASP.NET in Study4
Kyle Shen
 
SignalR實戰技巧 twmvc#17
SignalR實戰技巧 twmvc#17
twMVC
 
Vs2013新功能介紹 twMVC#11
Vs2013新功能介紹 twMVC#11
twMVC
 
twMVC#22 | 一個微信專案從0到.000的效能調教之路
twMVC#22 | 一個微信專案從0到.000的效能調教之路
twMVC
 
專案分層架構 twMVC#18
專案分層架構 twMVC#18
twMVC
 
twMVC#22 | 什麼鬼的IOC與DI
twMVC#22 | 什麼鬼的IOC與DI
twMVC
 
twMVC#28 | visual studio 2017 新功能介紹
twMVC#28 | visual studio 2017 新功能介紹
twMVC
 
twMVC#33聊聊如何自建 Facebook {廣告} 服務 with API
twMVC#33聊聊如何自建 Facebook {廣告} 服務 with API
twMVC
 
開發的效能與效率-twMVC#15
開發的效能與效率-twMVC#15
twMVC
 
前端工程師與室內裝修師傅的相似之處-twMVC#16
前端工程師與室內裝修師傅的相似之處-twMVC#16
twMVC
 
twMVC#29 -Learning Machine Learning with Movie Recommendation
twMVC#29 -Learning Machine Learning with Movie Recommendation
Mia Chang
 
Asp.net mvc 從無到有 -twMVC#2
Asp.net mvc 從無到有 -twMVC#2
twMVC
 
MVC實戰分享 分頁與排序相關技巧-tw mvc#13
MVC實戰分享 分頁與排序相關技巧-tw mvc#13
twMVC
 
Angular js入门分享 by 王栋
Angular js入门分享 by 王栋
栋 王
 
twMVC#41 The journey of source generator
twMVC#41 The journey of source generator
twMVC
 
ASP.NET MVC 善用網路資源快速完打造網站
ASP.NET MVC 善用網路資源快速完打造網站
twMVC
 
Mark_Resource
Mark_Resource
ibtesting
 
twMVC#29 | 當.Net Core 遇到AWS Lambda
twMVC#29 | 當.Net Core 遇到AWS Lambda
twMVC
 
twMVC#21 | 你所不知道的 Visual Studio
twMVC#21 | 你所不知道的 Visual Studio
twMVC
 
Angular.js & ASP.NET in Study4
Angular.js & ASP.NET in Study4
Kyle Shen
 
SignalR實戰技巧 twmvc#17
SignalR實戰技巧 twmvc#17
twMVC
 
Vs2013新功能介紹 twMVC#11
Vs2013新功能介紹 twMVC#11
twMVC
 
twMVC#22 | 一個微信專案從0到.000的效能調教之路
twMVC#22 | 一個微信專案從0到.000的效能調教之路
twMVC
 
專案分層架構 twMVC#18
專案分層架構 twMVC#18
twMVC
 
twMVC#22 | 什麼鬼的IOC與DI
twMVC#22 | 什麼鬼的IOC與DI
twMVC
 
twMVC#28 | visual studio 2017 新功能介紹
twMVC#28 | visual studio 2017 新功能介紹
twMVC
 

Similar to Bruce-輕鬆上手Asp.net web api 2.1.2 (20)

twMVC#14 | 輕鬆上手ASP.NET Web API 2
twMVC#14 | 輕鬆上手ASP.NET Web API 2
twMVC
 
ASP.NET MVC Web API -twMVC#8
ASP.NET MVC Web API -twMVC#8
twMVC
 
twMVC#08 | Web API
twMVC#08 | Web API
twMVC
 
ASP.Net WebAPI經驗分享
ASP.Net WebAPI經驗分享
國昭 張
 
Asp.net mvc 4 web api 開發簡介
Asp.net mvc 4 web api 開發簡介
Gelis Wu
 
使用 ASP.NET 5 實戰開發雲端應用程式
使用 ASP.NET 5 實戰開發雲端應用程式
Will Huang
 
ASP.NET MVC 6 新功能探索
ASP.NET MVC 6 新功能探索
Will Huang
 
twMVC#21 | 以實例說明ASP.NET Web API 服務的開發與測試過程
twMVC#21 | 以實例說明ASP.NET Web API 服務的開發與測試過程
twMVC
 
Introduction to ASP.NET MVC and MVC 5 Features
Introduction to ASP.NET MVC and MVC 5 Features
Jeff Chu
 
twMVC#01 | ASP.NET MVC 的第一次親密接觸
twMVC#01 | ASP.NET MVC 的第一次親密接觸
twMVC
 
RESTful API Design
RESTful API Design
Amigo 陳兆祥
 
Visual studio 2012 與 asp.net 4.5 (新功能與開發介紹) 第一天
Visual studio 2012 與 asp.net 4.5 (新功能與開發介紹) 第一天
Gelis Wu
 
Asp.net mvc 6 新功能初探
Asp.net mvc 6 新功能初探
Gelis Wu
 
Asp.Net Mvc 1.0
Asp.Net Mvc 1.0
Chui-Wen Chiu
 
20130823微軟雲端平台開發者日
20130823微軟雲端平台開發者日
twMVC
 
Asp.net mvc網站的從無到有
Asp.net mvc網站的從無到有
Wade Huang
 
Net 6 的 blazor 開發新視界
Net 6 的 blazor 開發新視界
Gelis Wu
 
ASP.NET Core 6.0 全新功能探索
ASP.NET Core 6.0 全新功能探索
Will Huang
 
twMVC#02 | ASP.NET MVC 從無到有
twMVC#02 | ASP.NET MVC 從無到有
twMVC
 
twMVC#32應用 ASP.NET WebAPI2 Odata 建置高互動性 APIS
twMVC#32應用 ASP.NET WebAPI2 Odata 建置高互動性 APIS
twMVC
 
twMVC#14 | 輕鬆上手ASP.NET Web API 2
twMVC#14 | 輕鬆上手ASP.NET Web API 2
twMVC
 
ASP.NET MVC Web API -twMVC#8
ASP.NET MVC Web API -twMVC#8
twMVC
 
twMVC#08 | Web API
twMVC#08 | Web API
twMVC
 
ASP.Net WebAPI經驗分享
ASP.Net WebAPI經驗分享
國昭 張
 
Asp.net mvc 4 web api 開發簡介
Asp.net mvc 4 web api 開發簡介
Gelis Wu
 
使用 ASP.NET 5 實戰開發雲端應用程式
使用 ASP.NET 5 實戰開發雲端應用程式
Will Huang
 
ASP.NET MVC 6 新功能探索
ASP.NET MVC 6 新功能探索
Will Huang
 
twMVC#21 | 以實例說明ASP.NET Web API 服務的開發與測試過程
twMVC#21 | 以實例說明ASP.NET Web API 服務的開發與測試過程
twMVC
 
Introduction to ASP.NET MVC and MVC 5 Features
Introduction to ASP.NET MVC and MVC 5 Features
Jeff Chu
 
twMVC#01 | ASP.NET MVC 的第一次親密接觸
twMVC#01 | ASP.NET MVC 的第一次親密接觸
twMVC
 
Visual studio 2012 與 asp.net 4.5 (新功能與開發介紹) 第一天
Visual studio 2012 與 asp.net 4.5 (新功能與開發介紹) 第一天
Gelis Wu
 
Asp.net mvc 6 新功能初探
Asp.net mvc 6 新功能初探
Gelis Wu
 
20130823微軟雲端平台開發者日
20130823微軟雲端平台開發者日
twMVC
 
Asp.net mvc網站的從無到有
Asp.net mvc網站的從無到有
Wade Huang
 
Net 6 的 blazor 開發新視界
Net 6 的 blazor 開發新視界
Gelis Wu
 
ASP.NET Core 6.0 全新功能探索
ASP.NET Core 6.0 全新功能探索
Will Huang
 
twMVC#02 | ASP.NET MVC 從無到有
twMVC#02 | ASP.NET MVC 從無到有
twMVC
 
twMVC#32應用 ASP.NET WebAPI2 Odata 建置高互動性 APIS
twMVC#32應用 ASP.NET WebAPI2 Odata 建置高互動性 APIS
twMVC
 
Ad

More from Study4TW (12)

如何攻破大型副本 大型專案的開發與團隊合作經驗 聊天室
如何攻破大型副本 大型專案的開發與團隊合作經驗 聊天室
Study4TW
 
使用下一代的Visual studio 14開發下一代的asp.net mvc v next ( mvc 6 )
使用下一代的Visual studio 14開發下一代的asp.net mvc v next ( mvc 6 )
Study4TW
 
James-版本控制
James-版本控制
Study4TW
 
windows phone 8.1 新功能與跨平台開發
windows phone 8.1 新功能與跨平台開發
Study4TW
 
ASP.NET MVC 快速上手
ASP.NET MVC 快速上手
Study4TW
 
SQL 語法入門 - SARG
SQL 語法入門 - SARG
Study4TW
 
使用Visual Studio 2010開發SQL
使用Visual Studio 2010開發SQL
Study4TW
 
Asp.Net MVC 4概念與新功能探討
Asp.Net MVC 4概念與新功能探討
Study4TW
 
Asp.Net MVC 一教就上手
Asp.Net MVC 一教就上手
Study4TW
 
Visual Studio 2013 新功能
Visual Studio 2013 新功能
Study4TW
 
使用Visual Studio 2013 進行敏捷開發
使用Visual Studio 2013 進行敏捷開發
Study4TW
 
真實環境的Asp.net MVC
真實環境的Asp.net MVC
Study4TW
 
如何攻破大型副本 大型專案的開發與團隊合作經驗 聊天室
如何攻破大型副本 大型專案的開發與團隊合作經驗 聊天室
Study4TW
 
使用下一代的Visual studio 14開發下一代的asp.net mvc v next ( mvc 6 )
使用下一代的Visual studio 14開發下一代的asp.net mvc v next ( mvc 6 )
Study4TW
 
James-版本控制
James-版本控制
Study4TW
 
windows phone 8.1 新功能與跨平台開發
windows phone 8.1 新功能與跨平台開發
Study4TW
 
ASP.NET MVC 快速上手
ASP.NET MVC 快速上手
Study4TW
 
SQL 語法入門 - SARG
SQL 語法入門 - SARG
Study4TW
 
使用Visual Studio 2010開發SQL
使用Visual Studio 2010開發SQL
Study4TW
 
Asp.Net MVC 4概念與新功能探討
Asp.Net MVC 4概念與新功能探討
Study4TW
 
Asp.Net MVC 一教就上手
Asp.Net MVC 一教就上手
Study4TW
 
Visual Studio 2013 新功能
Visual Studio 2013 新功能
Study4TW
 
使用Visual Studio 2013 進行敏捷開發
使用Visual Studio 2013 進行敏捷開發
Study4TW
 
真實環境的Asp.net MVC
真實環境的Asp.net MVC
Study4TW
 
Ad

Bruce-輕鬆上手Asp.net web api 2.1.2