简体   繁体   English

WCF,Web API,WCF REST和Web服务之间的区别?

[英]Difference between WCF, Web API, WCF REST and Web Service?

What is difference between WCF and Web API and WCF REST and Web Service? WCF和Web API以及WCF REST和Web服务有什么区别? Is WCF really so complicated that the webapi should be used? WCF真的如此复杂以至于应该使用webapi吗? Whether WebApi can do all the work and do not take advantage of others? WebApi能否完成所有工作而不利用其他工作?

The .Net framework has a number of technologies that allow you to create HTTP services such as Web Service, WCF and now Web API. .Net框架有许多技术允许您创建HTTP服务,例如Web Service,WCF和现在的Web API。 There are a lot of articles over the internet which may describe to whom you should use. 互联网上有很多文章可能描述你应该使用谁。

Web Service 网络服务

  • It is based on SOAP and return data in XML form. 它基于SOAP并以XML形式返回数据。
  • It support only HTTP protocol. 它仅支持HTTP协议。
  • It is not open source but can be consumed by any client that understands xml. 它不是开源的,但可以被任何理解xml的客户端使用。
  • It can be hosted only on IIS. 它只能在IIS上托管。

WCF WCF

  • It is also based on SOAP and return data in XML form. 它还基于SOAP并以XML格式返回数据。
  • It is the evolution of the web service(ASMX) and support various protocols like TCP, HTTP, HTTPS, Named Pipes, MSMQ. 它是Web服务(ASMX)的发展,支持TCP,HTTP,HTTPS,命名管道,MSMQ等各种协议。
  • The main issue with WCF is, its tedious and extensive configuration. WCF的主要问题是其繁琐而广泛的配置。
  • It is not open source but can be consumed by any client that understands xml. 它不是开源的,但可以被任何理解xml的客户端使用。
  • It can be hosted with in the applicaion or on IIS or using window service. 它可以在应用程序中或IIS上或使用窗口服务托管。

WCF Rest WCF休息

  • To use WCF as WCF Rest service you have to enable webHttpBindings. 要将WCF用作WCF Rest服务,您必须启用webHttpBindings。
  • It support HTTP GET and POST verbs by [WebGet] and [WebInvoke] attributes respectively. 它分别通过[WebGet]和[WebInvoke]属性支持HTTP GET和POST动词。
  • To enable other HTTP verbs you have to do some configuration in IIS to accept request of that particular verb on .svc files 要启用其他HTTP谓词,您必须在IIS中进行一些配置,以接受.svc文件上该特定谓词的请求
  • Passing data through parameters using a WebGet needs configuration. 使用WebGet通过参数传递数据需要配置。 The UriTemplate must be specified. 必须指定UriTemplate。
  • It support XML, JSON and ATOM data format. 它支持XML,JSON和ATOM数据格式。

Web API Web API

  • This is the new framework for building HTTP services with easy and simple way. 这是用简单方法构建HTTP服务的新框架。
  • Web API is open source an ideal platform for building REST-ful services over the .NET Framework. Web API是开源的,是通过.NET Framework构建REST-ful服务的理想平台。
  • Unlike WCF Rest service, it use the full feature of HTTP (like URIs, request/response headers, caching, versioning, various content formats) 与WCF Rest服务不同,它使用HTTP的全部功能(如URI,请求/响应头,缓存,版本控制,各种内容格式)
  • It also supports the MVC features such as routing, controllers, action results, filter, model binders, IOC container or dependency injection, unit testing that makes it more simple and robust. 它还支持MVC功能,例如路由,控制器,操作结果,过滤器,模型绑定器,IOC容器或依赖注入,单元测试使其更加简单和健壮。
  • It can be hosted with in the application or on IIS. 它可以在应用程序或IIS上托管。
  • It is light weight architecture and good for devices which have limited bandwidth like smart phones. 它是轻量级架构,适用于智能手机带宽有限的设备。
  • Responses are formatted by Web API's MediaTypeFormatter into JSON, XML or whatever format you want to add as a MediaTypeFormatter. 响应由Web API的MediaTypeFormatter格式化为JSON,XML或您要添加为MediaTypeFormatter的任何格式。

To whom choose between WCF or WEB API 在WCF或WEB API之间选择谁

  • Choose WCF when you want to create a service that should support special scenarios such as one way messaging, message queues, duplex communication etc. 如果要创建应支持特殊方案的服务(例如单向消息传递,消息队列,双工通信等),请选择WCF。
  • Choose WCF when you want to create a service that can use fast transport channels when available, such as TCP, Named Pipes, or maybe even UDP (in WCF 4.5), and you also want to support HTTP when all other transport channels are unavailable. 如果要创建可在可用时使用快速传输通道的服务(例如TCP,命名管道,甚至UDP(在WCF 4.5中)),请选择WCF,并且还希望在所有其他传输通道不可用时支持HTTP。
  • Choose Web API when you want to create a resource-oriented services over HTTP that can use the full features of HTTP (like URIs, request/response headers, caching, versioning, various content formats). 如果要通过HTTP创建可以使用HTTP的完整功能(如URI,请求/响应头,缓存,版本控制,各种内容格式)的面向资源的服务,请选择Web API。
  • Choose Web API when you want to expose your service to a broad range of clients including browsers, mobiles, iphone and tablets. 如果要将服务公开给广泛的客户,包括浏览器,手机,iPhone和平板电脑,请选择Web API。

Reference: http://www.dotnettricks.com 参考: http//www.dotnettricks.com
Author : Shailendra Chauhan 作者:Shailendra Chauhan

The .Net framework has a number of technologies that allow you to create HTTP services such as Web Service, WCF and now Web API. .Net框架有许多技术允许您创建HTTP服务,例如Web Service,WCF和现在的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 choices to build HTTP services on .NET framework. 现在有一天,你有很多选择在.NET框架上构建HTTP服务。 here you can read more: 在这里你可以阅读更多:

WCF vs ASP.NET Web API WCF与ASP.NET Web API

WCF Service vs ASP.NET Web Api WCF服务与ASP.NET Web Api

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM