Webservce、WCF、WebApi的区别
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 XML form.
-
It is the evolution of the web service(ASMX) and support various protocols like TCP, HTTP, HTTPS, Named Pipes, MSMQ.
-
The main issue with WCF is, its tedious and extensive configuration.
-
It is not open source but can be consumed by any client that understands xml.
-
It can be hosted with in the applicaion or on IIS or using window service.
WCF Rest
-
To use WCF as WCF Rest service you have to enable webHttpBindings.
-
It support HTTP GET and POST verbs by [WebGet] and [WebInvoke] attributes respectively.
-
To enable other HTTP verbs you have to do some configuration in IIS to accept request of that particular verb on .svc files
-
Passing data through parameters using a WebGet needs configuration. The UriTemplate must be specified
-
It support XML, JSON and ATOM data format.
Web API
-
This is the new framework for building HTTP services with easy and simple way.
-
Web API is open source an ideal platform for building REST-ful services over the .NET Framework.
-
Unlike WCF Rest service, it use the full featues of HTTP (like URIs, request/response headers, caching, versioning, various content formats)
-
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.
-
It can be hosted with in the application or on 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.
To whom choose between WCF or 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.
-
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.
-
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).
-
Choose Web API when you want to expose your service to a broad range of clients including browsers, mobiles, iphone and tablets.
转载:http://www.dotnet-tricks.com/Tutorial/webapi/JI2X050413-Difference-between-WCF-and-Web-API-and-WCF-REST-and-Web-Service.html
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 智能桌面机器人:用.NET IoT库控制舵机并多方法播放表情
· Linux glibc自带哈希表的用例及性能测试
· 深入理解 Mybatis 分库分表执行原理
· 如何打造一个高并发系统?
· .NET Core GC压缩(compact_phase)底层原理浅谈
· 手把手教你在本地部署DeepSeek R1,搭建web-ui ,建议收藏!
· 新年开篇:在本地部署DeepSeek大模型实现联网增强的AI应用
· Janus Pro:DeepSeek 开源革新,多模态 AI 的未来
· 互联网不景气了那就玩玩嵌入式吧,用纯.NET开发并制作一个智能桌面机器人(三):用.NET IoT库
· 【非技术】说说2024年我都干了些啥