REST (Representational State Transfer) and SOA (Service-Oriented Architecture) are two mainstream Architecture ideas in today's software Architecture and are becoming increasingly popular in the development process. As the next-generation communication technology on the Microsoft. NET platform, WCF also provides great support for them. So what are the differences and similarities between them .? This article will talk about this issue and use the Demo program.
The content of this design is as follows:
1. REST features
2. Characteristics of SOA
3. Commonalities Between REST and SOA
4. Differences between REST and SOA
5. Demo program description
* REST features.
First, give a picture:
It is based on the HTTP protocol and is a clear style built on the client/server architecture. The features are as follows:
1. All resources on the network are abstracted as resources. These resources have unique and unified resource identifiers.
(URI: Uniform Resource Identiter), these resources are described by us. These resources are specified using the HTTP Content Header type. Such as XML, JSON, HTML, and PNG.
2. service users operate resources through standard HTTP actions (Get, Put, Post, and Delete.
3. Operations on resources do not change its URI.
4. The interaction between the client and the server is stateless. Because of this stateless row, the server does not need to maintain the Context for each client
* SOA features
First, give a picture:
1. provide external services through the network endpoint.
2. coarse-grained service interfaces.
* Commonalities between REST and SOA
Although there are differences between REST and SOA, they all serve as different architectural styles of services and have the general attributes of services. The details are as follows:
1. Unified Service Contract interface and Service Interface
2. Loose coupling.
3. Access is allowed as long as you have permissions.
* Differences between REST and SOA
1. There is only one protocol in the rest style, namely HTTP. However, the WCF in SOA is connected to multiple protocols. Such as TCP, HTTP, and MSMQ.
2. usage is different. REST can be accessed through standard HTTP actions as long as the client can simulate HTTP requests. It uses the HTTPChannel pipeline, while
Protocol diversity. The pipelines used include HTTPChannel, TcpChannel, and RPC.
3. During REST hosting, you can select multiple boarding methods, but you must have IIS support (the boarding method will be described later ). WCF in SOA does not have this restriction.
* Demo program.
The program follows the instances used in the previous section and implements the REST and SOA services respectively. In the service, the definition and implementation of the contract are identical. To use the same REST protocol, the SOA server adopts the wsHttpBinding protocol. Consumers of REST and SOA services use the same client.
The program structure is as follows:
The client calls the SOA service using the following code:
1 using (ChannelFactory <ILog> factory = new ChannelFactory <ILog> ("SOAService "))
2 {
3 ILog log = factory. CreateChannel ();
4 List <LogEntity> listAll = log. GetAll ();
5 Console. WriteLine (string. Format ("{0} log records retrieved by the GetAll method", listAll. Count ));
6 Console. WriteLine ();
7 const string year = "2011 ";
8 const string month = "10 ";
9 List <LogEntity> list = log. GetMonthLog (year, month );
10 Console. writeLine (string. format ("The GetMonthLog method obtains {2} log records for {0} years {1} months", year, month, list. count ));
11}
The call code for REST is as follows:
1 HttpWebRequest request = WebRequest. Create ("http: // localhost: 27790/RESTService. svc/") as HttpWebRequest;
2 request. Method = "GET ";
3 HttpWebResponse response = request. GetResponse () as HttpWebResponse;
4 using (StreamReader reader = new StreamReader (response. GetResponseStream ()))
5 {
6 if (response. StatusCode = HttpStatusCode. OK)
7 {
8 Console. WriteLine (reader. ReadToEnd ());
9}
10}
As shown in:
Call the GetMonthLog method in REST, just replace URI with http://www.bkjia.com: 27790/RESTService. svc/Get/2011/10
If you are interested, try it.
Note: This article describes my personal understanding. If you are biased, I hope you can advise me. Thank you!
Author: tyb1222