Asp.Net Web API 和 WCF 服务有什么区别? [英] What is the difference between Asp.Net Web API and WCF Service?

查看:20
本文介绍了Asp.Net Web API 和 WCF 服务有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自过去几个月以来,这个 Asp.Net Web API 似乎是 Microsoft 的一个突出产品.它是 WS* 服务的替代品吗?它与 WCF 服务有何不同?我们在哪里可以看到它最适合网络应用程序开发?

解决方案

ASP.NET Web API 是一个框架,用于构建通过 HTTP 公开的 Web 服务.它非常适合(但不限于)构建 RESTful Web 服务.

此类 Web 服务是构建 SOAP RPC/WS* Web 服务的替代方案,因为它们更简单、重量更轻,并且客户端和服务器之间的耦合更少.

传统的WCF 服务"支持 SOAP RPC 而不是 REST,这些服务往往很复杂,并且在客户端和服务器之间具有紧密的耦合.广泛的互操作性可能变得难以实现.但是,传统的 WCF 服务可以通过多种协议进行通信 - TCP 对于内部服务(同一 DMZ 中的服务)特别有用.

(虽然 WCF 主要与 SOAP RPC 样式的服务相关联,但 WCF 中至少有 3 次尝试支持构建 RESTful Web 服务.这些尝试都已被 ASP.NET Web API 取代.)

ASP.NET Web API 最适合通过 HTTP 生成面向公众的 RESTful Web 服务(又名超媒体 API).为此,在开始使用 ASP.NET Web API 之前充分了解 REST 架构风格很重要.参见REST in Practice"、RESTful Web 服务手册"和使用 HTML5 和 Node 构建超媒体 API"等书籍.

Since last few months this Asp.Net Web API seems to be an highlighted product from Microsoft. Is it an alternative to WS* Service. How is it different than WCF Service? And where can we see it as a best fit in web application development?

解决方案

ASP.NET Web API is a framework for building web services that are exposed over HTTP. It is very well suited to (but not limited to) building RESTful web services.

Such web services are an alternative to building a SOAP RPC / WS* web services in that they are simpler, more light weight, and there's less coupling between client and server.

A traditional "WCF Service" supports SOAP RPC as opposed to REST, and these services tend to be complex and to have a tight coupling between client and server. Wide interoperability can become difficult to achieve. However, a traditional WCF Service can communicate over a wide variety of protocols - TCP being a particularly useful one for internal services (services in the same DMZ).

(While WCF is mostly associated with SOAP RPC-style services, there are at least three attempts in WCF to support the building of RESTful web services. These attempts have all been superseded by the ASP.NET Web API.)

ASP.NET Web API is a best fit for producing public facing RESTful web services - aka Hypermedia APIs - over HTTP. To do this, having a good understanding of the REST architectural style is important before you start using the ASP.NET Web API. See such books as "REST in Practice", "The RESTful Web Services Cookbook" and "Building Hypermedia APIs with HTML5 and Node".

这篇关于Asp.Net Web API 和 WCF 服务有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆