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

aka*_*rma 4 java rest soap web-services

肥皂和休息之间有什么区别

在设置一些新的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
Run Code Online (Sandbox Code Playgroud)

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

据我所知,最好的答案是" 这取决于要求 ".

现在我想知道哪些要求有利于哪些实现

什么时候应该选择肥皂和什么时候休息?请举例说明.

如果我错了,请纠正我.

有用的链接

谢谢

Rav*_*abu 9

使用REST

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

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

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

使用SOAP

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

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

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

看看这篇文章