Web API 和 WCF 的比较

现在有很多可用的技术允许你创建被不同客户端所消费的服务,这些客户端可能是Web应用程序、Windows应用程序和移动应用等。服务可以支持http协议或者其他协议。接下来的讨论仅限于ASP.NET Web API和WCF。

WCF(Windows Communication Foundation),使用WCF你可以构建安全可靠的服务,并且实现跨平台继承和平滑地交互。

Web API,一个用于构建HTTP服务的框架。现在我们每天都在使用手机、平板、apps以及各种不同类型的服务,Web API是一个简单可靠的平台,你能够用它来构建服务于大范围客户端的HTTP服务。使用Web API你可以创建完整的REST服务。

SOAP

SOAP(Simple Object Access Protocol)是微软所提出的用于创建在因特网上传输的结构化格式数据或消息的协议。SOAP是使用WCF和XML格式的主要基础。Web Service构建用于提供有关服务数据信息的WSDL(Web Services Description Language)文件。WSDL文件用于客户端理解服务中可用的方法。

REST

REST(Representational State Transfer)并非是像SOAP那样的协议。它是用来构建Web Services的一种架构设计模式。Web API使用这种模式来构建Web服务。从根本上讲,Web API是一种给客户端暴露服务终结点的资源驱动型架构。Web API支持完整的REST风格,它使用GET, PUT, POST, DELETE与客户端进行通讯。

交互性

RESTful服务(例如Web API)的特点是简单、轻量级、支持HTTP请求,而且易于客户端获取。它不像SOAP那样,需要客户端理解WSDL来实现服务。WSDL使用额外的配置和要求附加逻辑,这样可能对于很多设备例如手机、智能电视、平板电脑等就不是那么的便利。正是因为WCF支持多种协议,所以它能够被众多使用不同协议(HTTP、TCP、MSMQ等)的客户端消费。

配置管理

相对于Web API,客户端需要使用更多的配置来获取WCF的服务。WCF使用了更多的配置项(例如终结点、行为等)来暴露服务。但是Web API有更多规范来为客户端定制服务。

速度

由于RESTful服务使用HTTP协议和HTTP的请求/响应较SOAP轻巧,因此如果你打算为低流量设备或手机端构建服务,Web API会是最佳之选。相较于SOAP,HTTP的请求/响应可读性更高,因为SOAP包含了header、body等更为复杂的元素。

安全

WCF提供了企业级别的高级别的安全等级,它使用了WS-I标准来提供安全服务。Web API使用了Web标准的安全措施,例如基本验证、token验证和更复杂的OAuth,Web API显得更加灵活。如果你需要验证外部服务例如谷歌、facebook等,那么使用SOAP。

综上所述,我们似乎难以决定哪个更好。但是,我们能得出两点结论。一,如果你需要构建一个用于不同平台的服务,那么请使用WCF;二,如果你需要构建基于因特网的服务,那么请使用Web API。

WCF与Web API 区别(应用场景)

WCF、WebAPI、WCFREST、WebService之间的区别

时间: 2024-08-03 19:30:23

Web API 和 WCF 的比较的相关文章

Difference between WCF and Web API and WCF REST and Web Service

The .Net framework has a number of technologies that allow you to create HTTP services such as Web Service, WCF and now Web API. There are a lot of articles over the internet which may describe to whom you should use. Now a days, you have a lot of ch

选择Web API还是WCF

ASP.NET WCF是.NET平台服务开发的一站式框架,那么为什么还要有ASP.NET Web API呢?简单来说,ASP.NET Web API的设计和构建只考虑了一件事情,那就是HTTP,而WCF的设计主要是考虑SOAP和WS-*. WCF已经出现好多年了,相对来说ASP.NET Web API还是个小孩子,但是不意味着ASP.NET Web API要代替WCF,在不同的场合,它们各有长处.ASP.NET Web API非常轻量,在功能和灵活性上都不能和WCF相比.如果你的服务是基于TCP

WCF 、Web API 、 WCF REST 和 Web Service 的区别

The .Net framework has a number of technologies that allow you to create HTTP services such as Web Service, WCF and now Web API. There are a lot of articles over the internet which may describe to whom you should use. Now a days, you have a lot of ch

[Solution] 使用Autofac在MVC、Web API、WCF中实现IOC

小分享:我有几张阿里云优惠券,用券购买或者升级阿里云相应产品最多可以优惠五折!领券地址:https://promotion.aliyun.com/ntms/act/ambassador/sharetouser.html?userCode=ohmepe03 本来想聊一下面试过程的,1个星期面了6家,4家当场给offer,2家技术通过(1家没下文,1家复试).从中也学习到一些东西,先还是继续Coding吧. 官网:http://autofac.org/ 下载:Install-Package Auto

转 Difference between WCF and Web API and WCF REST and Web Service

http://www.dotnet-tricks.com/Tutorial/webapi/JI2X050413-Difference-between-WCF-and-Web-API-and-WCF-REST-and-Web-Service.html Posted By : Shailendra Chauhan, 05 Apr 2013 Updated On : 13 Apr 2013 Total Views : 126,254 Keywords : web api vs wcf vs wcf r

WCF、Web API、WCF REST、Web Service 区别

Web Service It is based on SOAP and return data in XML form. It support only HTTP protocol. It is not open source but can be consumed by any client that understands xml. It can be hosted only on IIS. WCF It is also based on SOAP and return data in XM

ASP.NET Web API——选择Web API还是WCF

WCF是.NET平台服务开发的一站式框架,那么为什么还要有ASP.NET Web API呢?简单来说,ASP.NET Web API的设计和构建只考虑了一件事情,那就是HTTP,而WCF的设计主要是考虑SOAP和WS-*. WCF已经出现好多年了,相对来说ASP.NET Web API还是个小孩子,但是不意味着ASP.NET Web API要代替WCF,在不同的场合,它们各有长处.ASP.NET Web API非常轻量,在功能和灵活性上都不能和WCF相比.如果你的服务是基于TCP的,或者支持更多

Difference between WCF and Web API and WCF REST and Web Service[转]

Web Service It is based on SOAP and return data in XML form. It support only HTTP protocol. It is not open source but can be consumed by any client that understands xml. It can be hosted only on IIS. WCF It is also based on SOAP and return data in XM

WCF、Web API、WCF REST、Web Service比较

原文地址:http://www.dotnet-tricks.com/Tutorial/webapi/JI2X050413-Difference-between-WCF-and-Web-API-and-WCF-REST-and-Web-Service.html WCF 1.基于Soap协议,以XML形式返回. 2.是Web Service的进化 支持多种协议:TCP,HTTP,HTTPS,命名管道,消息队列. 3.缺点:冗长的大量配置. 4.不开源,但是可以被懂xml的定制. 5.可以部署在应用.