In the. NET framework, there are many techniques for creating HTTP protocol-based services, such as Web service, WCF,WCF rest, Web API, and so on. There are a lot of articles on the internet to teach us how to develop and use these technologies, but it does not explain the relationship between them, after a period of access to information, my understanding is now organized as follows.
Web Service:
- Based on SOAP, only the HTTP protocol is supported.
- The data transfer format is XML.
- Can only be deployed on IIS.
Wcf:
- SOAP-based, supports multiple transport protocols such as HTTP,HTTPS,TCP,MSMQ, named Pipes, and so on.
- The data transfer format is XML.
- Service configuration is cumbersome.
- Can host in an application, IIS, or Windows service.
WCF rest:
- The webhttpbindings node needs to be configured.
- The data transfer format can be XML, JSON, Atom, and so on.
- HTTP GET and post operations are supported by default, and additional HTTP operations such as put, delete, and so on can be supported by extra configuration of acceptable request in IIS.
- The UriTemplate template must be specified when the parameter is passed in WebGet mode.
Web API:
- is a lightweight framework for building HTTP services, which is in the. NET platform, the ideal framework for building restful Web service.
- Compared to the WCF Rest service, the Web API provides all the features of HTTP, such as URIs, Request/response headers, caching, versioning, and various content format.
- It also supports MVC's features.
- Can host in the application and IIS.
- Applicable to a variety of clients, such as browsers, mobile apps, PC-side applications and so on.
- Response are serialized into JSON, XML, or other kinds of formats.
When to use WCF or Web APIs:
- Use WCF if you have the following special scenarios: one-way messages, Message Queuing, duplex communication, and so on.
- WCF is recommended when transmission channels are not limited to HTTP, such as TCP, UDP, and so on.
- The Web API is recommended when you want to create a resource-oriented service or want to support all of the features of HTTP.
- The Web API is recommended when you need to support multiple clients.
Differences between Web service, WCF, WCF rest, Web API