程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> 【翻譯】ASP.NET Web API是什麼?,asp.netapi

【翻譯】ASP.NET Web API是什麼?,asp.netapi

編輯:C#入門知識

【翻譯】ASP.NET Web API是什麼?,asp.netapi


參考頁面:

http://www.yuanjiaocheng.net/entity/linq-to-entities-projection.html

http://www.yuanjiaocheng.net/entity/dbset-class.html

http://www.yuanjiaocheng.net/entity/dbentityentry-class.html

http://www.yuanjiaocheng.net/entity/change-tracking.html

http://www.yuanjiaocheng.net/entity/Persistence-in-EF.html

說明:隨微軟ASP.NET MVC 4一起發布的還有一個框架,叫做ASP.NET Web API。目前國內關注這項技術的人似乎還很少,這方面的文章也不多見。開發Web應用程序也許可以只用MVC這樣的技術,而不用這項Web API技術,但如果用了,會給你的應用程序帶來極大的好處。為此,本人轉載並翻譯了以下這篇文章,後面還會陸續翻譯該項技術的一些官方教程。大家一起學習,共同提高。

Microsoft ASP.NET: What's This New Web API?
微軟ASP.NET:新的Web API是什麼?

摘自:http://www.devproconnections.com/article/asp/microsoft-aspnet-web-api-142516

Don Kiely explains why Microsoft's Web API shines as a new technology for developers
Don Kiely解釋為什麼微軟的Web API是開發人員的一項耀眼的新技術。

WhatsAPI
Don Kiely
Dev Pro
InstantDoc ID #142516
March 08, 2012 08:00 AM

After a respite in 2011 from new product mania, Microsoft is on a tear in 2012 to release early versions for many of its development tools. In the past couple of weeks we've seen a preview for Visual Studio 2011 and ASP.NET MVC 4. We also got our first look at the SQL Server 2012 release candidate. These new releases mark an exciting time for technology, even if it means reevaluating these technologies and determining what skills developers should learn and focus on.
經過2011新產品狂熱的一段喘息之後,微軟2012年猛然發布了許多開發工具的早期版本。在前幾個星期我們看到了Visual Studio 2011和ASP.NET MVC 4的預覽版。我們也拿到了SQL Server 2012預發行版。這些最新發布標志著技術令人激動的時刻,盡管這僅意味著對這些技術的重新評估,並決定著開發人員應當學習和關注哪些技能。

One truly new and exciting technology for Microsoft is the Web API. I wasn't initially enthusiastic about this API, because it seemed to be another web service that's similar to the RESTful API. Do we really need another API when we already have ASP.NET Web Services and Windows Communication Foundation (WCF), or has Microsoft gone nutty about these kinds of APIs just as it has with data-access APIs?
一項真正全新且令人興奮的微軟技術是Web API。我最初並不熱衷於這個API,因為它似乎只是類似於REST化API的另一項web服務。在已經有了ASP.NET Web Services(ASP.NET Web服務)和Windows Communication Foundation(Windows通信基礎 — WCF)時,還真正需要另外一種API嗎?或者,微軟已經陷入瘋狂制作各種API,就像它做數據訪問API那樣?

I won't address the last part of that question—Microsoft seems pretty nutty at times—but I'm really starting to warm up to the new Web API, particularly because it's solidified into what appears to be the actual release API. I've come to realize that the reason for this is that the Web API feels natural and seems to fit in with the kinds of applications that I build. The Web API is far more than the relatively basic and hard-to-secure ASP.NET Web Services and the mind-numbingly complex WCF that always feels like a gross overkill for most things a website needs to do. At least this situation is true for the kinds of applications that I build most often these days.
我沒有注意到問題的後一部分 — 微軟有時確實是相當瘋狂的 — 但我對這個新的Web API真正開始熱衷起來了。我開始認識到,這麼做的原因是Web API感覺自然,而且它似乎適合於我所建立的各種應用程序。Web API遠遠超過了相對基本且難以安全的ASP.NET Web服務,而極為復雜的WCF總讓人感覺對於web網站要做的事件就像殺雞用了牛刀。至少,對於我這些日子最經常建立的各種應用程序而言,情況確實是這樣。

I've outlined some pretty subjective reasons for why I like the new Web API. From an objective and raw technology perspective, the Web API is designed and lives for HTTP. One complex problem with WCF is that it provides everything for everyone for every transport protocol, as Matt Milner explains in his blog post. You have to do some work to use WCF over HTTP. In contrast, the Web API is designed from the ground up to make good use of HTTP, warts and all. The Web API isn't exactly lightweight, but with only one protocol to support the API, it doesn't have a lot of excess baggage.
我概括了為什麼喜歡這個新的Web API的一些相當主觀的原因。從客觀和原始技術的觀點看,Web API是為HTTP而設計和存在的。WCF的一個復雜問題是它對每一個傳輸協議提供了方方面面的東西,就像Matt Milner在他的博客文章所解釋的那樣。你必須做一些工作才能將WCF運用於HTTP。與之相反,Web API毫無保留地就是圍繞充分利用HTTP而設計的。Web API其實並不是輕量級的,但它只針對一個協議來支持API,它不會產生很多超重的包袱。

The other thing that I like about the Web API is that it reflects the direction in which the web is headed. As Scott Guthrie points out in the first part of his blog post series about the Web API, many large websites are exposing Web APIs to make their services available to third-party applications (he cites Facebook, Twitter, LinkedIn, and Netflix as examples). He also lists a bunch of reasons why a Web API is a good solution, including a modern HTTP programming model. It's about time Microsoft got around to providing this model!
我喜歡Web API的另一件事是,它反映了web前進的方向。正如Scott Guthrie在他關於Web API系列文章的第一部分(中文版網址:http://blogs.msdn.com/b/scottgu/archive/2012/03/26/asp-net-web-api.aspx)所指出的那樣,許多大型網站都暴露了Web API,以使第三方應用程序能運用它們的服務(他例證了Facebook、Twitter、LinkedIn,以及Netflix等)。他也列出了一打理由,以說明為什麼Web API是一種好的解決方案,包括一個“現代HTTP編程模型”。現在,已經到了微軟提供這種模型的時候了!

I love the close integration of the Web API with ASP.NET MVC. Microsoft chose to implement custom Web APIs by using the well-established controller model. This makes sense because a lot of people were already implementing custom Web APIs by using MVC controllers that return JSON data to the client. That's a slick solution, and the Web API just makes it better. The only big difference is that a Web API controller implements ApiController class instead of Controller class, which in turn implements the IHttpController interface. ApiController is a relatively simple class in the System.Web.Http namespace, so it isn't tied exclusively to ASP.NET MVC, but it understands the HTTP protocol and most of its common verbs.
我喜歡Web API與ASP.NET MVC的密切集成。微軟通過運用建立良好的控制器模型來選擇實現自定義Web API。這是有意義的,因為,通過使用MVC的控制器把JSON數據返回給客戶端的辦法,很多人都已經實現了自定義Web API。這是一個平滑的解決方案,而且Web API恰恰使之更好。唯一大的差別是Web API控制器實現的是ApiController類,而不是Controller類,它轉而實現了IHttpController接口。ApiController是System.Web.Http命名空間中的一個相對簡單的類,因此它並未專門綁定於ASP.NET MVC,但它能夠理解HTTP協議及其大多數常規謂詞。

Best of all, the API is available to a wide variety of clients, including mobile applications. In fact, this fact is probably its biggest selling point. Web applications are increasingly not limited to applications that run in a desktop browser.
最好原因是,這種API可用於十分廣泛的客戶端,包括移動應用程序。事實上,這一事實可能是它最大的賣點。Web應用程序已經日益不僅限於運行在桌面浏覽器的應用程序了。

I'm not as big a fan of Microsoft's Web API as I am of Entity Framework, but I can already feel the tug. It'll be interesting to see how widely used this new technology becomes when it's finally released, but right now Web API is looking like a winner.
我是實體框架而不是微軟Web API的大粉絲,但我已經能夠感覺到這種拽力。看到新技術在它最終發布時變得廣泛使用是很有趣的,而現在,Web API漸漸看起來像是一個贏家。

 

看完此文如果覺得有所收獲,請給個推薦

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved