【问题标题】:When to use Soap and when to use Rest [closed]何时使用 Soap 以及何时使用 Rest [关闭]
【发布时间】:2015-10-12 18:46:34
【问题描述】:

肥皂和休息有什么区别

在设置一些新的 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 和 soap 中的安全性。

在我看来,最好的答案是“这取决于要求”。

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

什么时候应该首选肥皂,什么时候应该休息?请举例说明。

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

useful link

谢谢

【问题讨论】:

标签: java web-services rest soap


【解决方案1】:

REST 用于

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

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

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

SOAP 用于

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

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

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

看看这个article

【讨论】:

    猜你喜欢
    • 2012-03-26
    • 2015-02-16
    • 2021-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-25
    • 1970-01-01
    • 2013-09-23
    相关资源
    最近更新 更多