何时使用Soap以及何时使用Rest

时间:2015-10-12 18:46:34

标签: java web-services rest soap

肥皂与休息有什么区别

当设置一些新的Web服务或集成环境时,会多次提出此问题。 哪一个更好。

我知道一些基本的区别,下面提到:

(1)Rest is based on http protocol (get,put,post,delete) , treating everything as a resource.
whereas SOAP is transport agnostic

(2)Soap works only with xml , Rest works with json/xml both.

(3)rest do not provide schema definition when implemented as json,
Soap will always provide schema definitions. 
It will be easy to understand request/response schema and
 their data type constraints when viewing schema information via WSDL by any client.

(4)The step of wsdl creation makes it difficult to make any changes in your 
schema classes while implementing in soap.
Rest implementation is quite easy, we just need to make changes in pojo classes.

(5)Soap provides default error handling via faults.
We can also create our own custom faults.
In Rest we need to handle all error messages explicitly.

(6)Soap provides SoapHandler to intercept request both at client/server side 
with both request/response.
we can use filters of j2ee or interceptors of Spring to intercept calls.

(7)Soap is fixed defined set of protocol, whereas rest is architectural style.
While implementing REST, developers can follow any rule,
 for example 
not using http protocol in well defined way.
While in Soap message part is defined as envelope.

one envelope=header+body+fault+attachment

我仍在学习这些概念,并没有在休息和肥皂方面为这些服务的安全工作。

根据我的说法,最好的答案是" 这取决于要求"。

现在我想知道哪些要求支持哪种实现

肥皂何时应该首选,什么时候应该使用REST?请举例说明。

如果我在某处错了,请纠正我。

useful link

由于

1 个答案:

答案 0 :(得分:7)

使用 REST

  1. 完全没有状态的操作: 如果您需要无状态CRUD(创建,读取,更新和删除)操作,那么REST就是

    < / LI>
  2. 缓存情况: 如果由于完全无状态操作而可以缓存信息

  3. 有限带宽: 与REST响应相比,SOAP XML响应消耗更多带宽

  4. 使用 SOAP 作为

    1. 异步处理和调用: 如果您的应用程序需要有保证的可靠性和安全性

    2. 正式合同:如果双方(提供商和消费者)必须就交换格式达成一致

    3. 有状态操作: 如果应用程序需要上下文信息和会话状态管理

    4. 看看这个article