为什么基于 SOAP 的 Web 服务不是 RESTful? [英] Why isn't SOAP-based web service RESTful?

查看:46
本文介绍了为什么基于 SOAP 的 Web 服务不是 RESTful?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 RESTful 是一种架构风格,但究竟是什么让基于 SOAP 的 Web 服务不计入 RESTful?

I understand RESTful is an architecture style, but what exactly makes SOAP-based web service not count for RESTful?

我不清楚下面哪一点(来自 维基百科)不符合 SOAP.

It's not clear to me which points below (from Wikipedia), is not conformed by SOAP.

  1. 客户端-服务器
  2. 无国籍
  3. 可缓存
  4. 分层系统
  5. 按需代码(可选)
  6. 统一界面
    • 资源识别
    • 通过这些表示操纵资源
    • 自我描述信息
    • 超媒体作为应用程序状态的引擎

编辑:我刚刚遇到了这个 总结得很好.

EDIT: I just came across this which summaries it pretty well.

REST 不是 RPC,RPC 说,定义一些做某事的方法"而 REST 说,定义一些资源,他们将拥有这些方法".这是一个微妙但至关重要的区别,当给定一个 URI 时,任何人都知道他们可以通过预定义与之交互一套方法和接收标准作为回报的 HTTP 响应.所以给出http://www.peej.co.uk/ 我知道我可以对其发出 GET 并接收回有意义的东西.然后我可以尝试在其上放置一个 PUT 来改变它,然后收到有意义的 HTTP 错误代码因为我无权干涉与它.

REST is not RPC, RPC says, "define some methods that do something" whereas REST says, "define some resources and they will have these methods". It is a subtle but vital difference, when given a URI anyone knows they can interact with it via the predefined set of methods and receive standard HTTP responses in return. So given http://www.peej.co.uk/ I know I can issue a GET on it and receive something meaningful back. I may then try a PUT on it to change it and receive a meaningful HTTP error code since I'm not authorised to meddle with it.

推荐答案

SOAP 遵循 RPC 模式.SOAP API 描述了一系列方法及其参数和返回值,您可以从代码中调用这些方法.有一个编组步骤将其转换为它的网络表示.

SOAP follows the RPC pattern. A SOAP API describes a series of methods, along with their parameters and return values, that you can call from your code. There's a marshaling step that converts this into it's network representation.

REST 绝不是 RPC.REST API 描述了一系列资源,以及一组可以对它们进行操作的动词(通常是 HTTP 的 GET、POST、PUT、DELETE).

REST is never RPC. A REST API describes a series of resources, along with a set of verbs (typically HTTP's GET, POST, PUT, DELETE) that can act on them.

直接回答您的问题:SOAP 主要违反了第 6 点(它没有提供跨 API 的统一动词集).它也违反了第 2 点(服务器可以为每个客户端维护状态),因此也违反了第 3 点(状态阻止缓存).

To answer your question directly: SOAP primarily violates point 6 (it doesn't provide a uniform set of verbs across APIs). It also violates point 2 (the server can maintain state for each client), and as a result point 3 as well (state prevents caching).

这篇关于为什么基于 SOAP 的 Web 服务不是 RESTful?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆