Java 中 SOAP 和 RESTful Web 服务之间的主要区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2131965/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 03:55:35  来源:igfitidea点击:

Main differences between SOAP and RESTful web services in java

javasoaprest

提问by Gandalf StormCrow

Follow up question to this post:

跟进此帖子的问题:

For now I have a slight idea about the differences between SOAP and RESTful Services.

现在我对 SOAP 和 RESTful 服务之间的区别有一些了解。

My question is when I should use SOAP, and when I should use RESTful; which one is "better" when it comes to performance/speed or request handling?

我的问题是什么时候应该使用 SOAP,什么时候应该使用 RESTful;在性能/速度或请求处理方面,哪一个“更好”?

I'm implementing for the first time in RESTful(java) and I want know more about it; I've dealt with SOAP before.

我是第一次在 RESTful(java) 中实现,我想了解更多;我以前处理过 SOAP。

采纳答案by dj_segfault

REST is almost always going to be faster. The main advantage of SOAP is that it provides a mechanism for services to describe themselves to clients, and to advertise their existence.

REST 几乎总是会更快。SOAP 的主要优点是它为服务提供了一种机制,可以向客户端描述它们自己,并通告它们的存在。

REST is much more lightweight and can be implemented using almost any tool, leading to lower bandwidth and shorter learning curve. However, the clients have to know what to send and what to expect.

REST 更轻量级,几乎可以使用任何工具实现,从而降低带宽和缩短学习曲线。但是,客户必须知道要发送什么以及期望什么。

In general, When you're publishing an API to the outside world that is either complex or likely to change, SOAP will be more useful. Other than that, REST is usually the better option.

通常,当您向外部世界发布复杂或可能更改的 API 时,SOAP 会更有用。除此之外,REST 通常是更好的选择。

回答by CharithJ

  1. REST has no WSDL[Web Description Language] interface definition.

  2. REST is over HTTP, but SOAP can be over any transport protocols such as HTTP, FTP, SMTP, JMS etc.

  1. REST 没有 WSDL[Web Description Language] 接口定义。

  2. REST 基于 HTTP,但 SOAP 可以基于任何传输协议,例如 HTTP、FTP、SMTP、JMS 等。

回答by Kalidoss.M

REST is an architecture. REST will give human-readable results. REST is stateless. REST services are easily cacheable.

REST 是一种架构。REST 将提供人类可读的结果。REST 是无状态的。REST 服务很容易缓存。

SOAP is a protocol. It can run on top of JMS, FTP, Http.

SOAP 是一种协议。它可以运行在 JMS、FTP、Http 之上。

回答by salman khalid

REST vs SOAP Web Services

I am seeing a lot of new web services are implemented using a REST style architecture these days rather than a SOAP one. Lets step back a second and explain what REST is.

What is a REST Web Service

The acronym REST stands for Representational State Transfer, this basically means that each unique URL is a representation of some object. You can get the contents of that object using an HTTP GET, to delete it, you then might use a POST, PUT, or DELETE to modify the object (in practice most of the services use a POST for this).

Who's using REST?

All of Yahoo's web services use REST, including Flickr, del.icio.us API uses it, pubsub, bloglines, technorati, and both eBay, and Amazon have web services for both REST and SOAP.

Who's using SOAP?

Google seams to be consistent in implementing their web services to use SOAP, with the exception of Blogger, which uses XML-RPC. You will find SOAP web services in lots of enterprise software as well.

REST vs SOAP

As you may have noticed the companies I mentioned that are using REST api's haven't been around for very long, and their apis came out this year mostly. So REST is definitely the trendy way to create a web service, if creating web services could ever be trendy (lets face it you use soap to wash, and you rest when your tired). The main advantages of REST web services are:

Lightweight - not a lot of extra xml markup Human Readable Results Easy to build - no toolkits required SOAP also has some advantages:

Easy to consume - sometimes Rigid - type checking, adheres to a contract Development tools For consuming web services, its sometimes a toss up between which is easier. For instance Google's AdWords web service is really hard to consume (in CF anyways), it uses SOAP headers, and a number of other things that make it kind of difficult. On the converse, Amazon's REST web service can sometimes be tricky to parse because it can be highly nested, and the result schema can vary quite a bit based on what you search for.

Which ever architecture you choose make sure its easy for developers to access it, and well documented.

REST 与 SOAP Web 服务

我现在看到很多新的 Web 服务是使用 REST 风格的架构而不是 SOAP 架构来实现的。让我们退后一步解释什么是 REST。

什么是 REST Web 服务

首字母缩略词 REST 代表 Representational State Transfer,这基本上意味着每个唯一的 URL 都是某个对象的表示。您可以使用 HTTP GET 获取该对象的内容,要删除它,然后您可以使用 POST、PUT 或 DELETE 来修改该对象(实际上大多数服务为此使用 POST)。

谁在使用 REST?

Yahoo 的所有 Web 服务都使用 REST,包括 Flickr、del.icio.us API 使用它、pubsub、bloglines、technorati,以及 eBay 和 Amazon 都有适用于 REST 和 SOAP 的 Web 服务。

谁在使用 SOAP?

除了使用 XML-RPC 的 Blogger 之外,Google 接缝在实现其 Web 服务以使用 SOAP 方面保持一致。您还会在许多企业软件中找到 SOAP Web 服务。

REST 与 SOAP

您可能已经注意到我提到的使用 REST api 的公司成立时间不长,他们的 api 大多在今年推出。所以 REST 绝对是创建 Web 服务的流行方式,如果创建 Web 服务可能会流行的话(让我们面对现实,你用肥皂洗,累了就休息)。REST Web 服务的主要优点是:

轻量级 - 没有很多额外的 xml 标记 人类可读的结果 易于构建 - 不需要工具包 SOAP 也有一些优点:

易于使用 - 有时是刚性的 - 类型检查,遵守合同 开发工具 对于使用 Web 服务,有时在两者之间进行折腾更容易。例如,Google 的 AdWords 网络服务真的很难使用(无论如何在 CF 中),它使用 SOAP 标头,以及许多其他使它变得困难的东西。相反,Amazon 的 REST Web 服务有时难以解析,因为它可以高度嵌套,并且结果架构可能会根据您搜索的内容而有很大差异。

无论您选择哪种架构,都可以确保开发人员可以轻松访问它,并且有据可查。

Freitag, P. (2005). "REST vs SOAP Web Services". Retrieved from http://www.petefreitag.com/item/431.cfm on June 13, 2010

Freitag, P. (2005)。“REST 与 SOAP Web 服务”。2010 年 6 月 13 日从 http://www.petefreitag.com/item/431.cfm 检索

回答by kapil das

SOAP

肥皂

Simple Object Access Protocol (SOAP) standard an XML language defining a message architecture and message formats, is used by Web services it contain a description of the operations. WSDL is an XML-based language for describing Web services and how to access them. will run on SMTP,HTTP,FTP etc. Requires middleware support, well defined mechanisam to define services like WSDL+XSD, WS-Policy SOAP will return XML based data

简单对象访问协议 (SOAP) 标准是一种定义消息体系结构和消息格式的 XML 语言,由 Web 服务使用,它包含对操作的描述。WSDL 是一种基于 XML 的语言,用于描述 Web 服务以及如何访问它们。将在 SMTP、HTTP、FTP 等上运行。需要中间件支持,定义良好的机制来定义 WSDL+XSD 等服务,WS-Policy SOAP 将返回基于 XML 的数据

RESTRepresentational State Transfer (RESTful) web services. they are second generation Web Services. RESTful web services, communicate via HTTP than SOAP-based services and do not require XML messages or WSDL service-API definitions. for REST no middleware is required only HTTP support is needed.WADL Standard, REST can return XML, plain text, JSON, HTML etc

REST 具象状态传输 (RESTful) Web 服务。它们是第二代 Web 服务。RESTful Web 服务,通过 HTTP 而非基于 SOAP 的服务进行通信,并且不需要 XML 消息或 WSDL 服务-API 定义。对于 REST,不需要中间件,只需要 HTTP 支持。WADL 标准,REST 可以返回 XML、纯文本、JSON、HTML 等

回答by Sudhakar_Jayaraman

Soap Web-services :

肥皂网络服务:

  1. If your application needs a guaranteed level of reliability and security then SOAP offers additional standards to ensure this type of operation.
  2. If both sides (service provider and service consumer) have to agree on the exchange format then SOAP gives the rigid specifications for this type of interaction.
  1. 如果您的应用程序需要有保证的可靠性和安全性级别,那么 SOAP 提供了额外的标准来确保此类操作。
  2. 如果双方(服务提供者和服务消费者)必须就交换格式达成一致,那么 SOAP 会为这种类型的交互提供严格的规范。

RestWeb-Services :

RestWeb-服务:

  1. Totally stateless operations: for stateless CRUD (Create, Read, Update, and Delete) operations.
  2. Caching situations: If the information needs to be cached.
  1. 完全无状态操作:用于无状态 CRUD(创建、读取、更新和删除)操作。
  2. 缓存情况:如果信息需要缓存。

回答by vidya k n

REST is easier to use for the most part and is more flexible.Unlike SOAP, REST doesn't have to use XML to provide the response. We can find REST-based Web services that output the data in Command Separated Value (CSV), JavaScript Object Notation (JSON) and Really Simple Syndication (RSS). We can obtain the output we need in a form that's easy to parse within the language we need for our application.REST is more efficient(use smaller message formats),fast and closer to other Web technologies in design philosophy

大多数情况下,REST 更易于使用且更灵活。与 SOAP 不同,REST 不必使用 XML 来提供响应。我们可以找到基于 REST 的 Web 服务,它们以命令分隔值 (CSV)、JavaScript 对象表示法 (JSON) 和真正简单的联合 (RSS) 格式输出数据。我们可以在我们的应用程序所需的语言中以易于解析的形式获得我们需要的输出。REST 更高效(使用更小的消息格式)、快速且在设计理念上更接近其他 Web 技术

回答by Anil Kumar B

SOAP web service always make a POST operation whereas using REST you can choose specific http methods like GET,POST,PUT,DELETE. Example: to get an item using SOAP you should create a request xml but in the case of REST you can just specify the item id in the url itself.

SOAP Web 服务始终执行 POST 操作,而使用 REST 您可以选择特定的 http 方法,例如 GET、POST、PUT、DELETE。示例:要使用 SOAP 获取项目,您应该创建一个请求 xml,但在 REST 的情况下,您只需在 url 本身中指定项目 ID。

回答by Waqas Ahmed

Rest VS SOAP

休息 VS 肥皂

SOAP:

肥皂:

? SOAP is simple object access protocol that run on TCP/UDP/SMTP.
? SOAP read and write request response messages in XML format.
? SOAP uses interface in order to define the services.
? SOAP is more secure as it has its own security and well defined standards.
? SOAP follows RPC and Document style to define web services.
? SOAP uses SOAP-UI as client tools for testing.

? SOAP 是运行在 TCP/UDP/SMTP 上的简单对象访问协议。
? SOAP 以 XML 格式读取和写入请求响应消息。
? SOAP 使用接口来定义服务。
? SOAP 更安全,因为它有自己的安全性和明确定义的标准。
? SOAP 遵循 RPC 和文档风格来定义 Web 服务。
? SOAP 使用 SOAP-UI 作为客户端工具进行测试。

REST

休息

? REST is representational state transfer that uses underlying HTTP protocols.
? REST is stateless.
? REST is an architectural style that is used to describe and define web services.
? REST can read and write request response messages in JSON/XML/Plain HTML.
? REST uses URI for each resource that is used in web service.A resource can be image text method etc.
? REST uses set of VERBs like HTTP's GET, POST, PUT, DELETE.
? REST is easy to develop and easy to manage as compared to SOAP UI.
? REST has light weight client tools or plugins that can easily be integrated inside browser.
? REST services are cache able.

? REST 是使用底层 HTTP 协议的代表性状态传输。
? REST 是无状态的。
? REST 是一种架构风格,用于描述和定义 Web 服务。
? REST 可以读取和写入 JSON/XML/Plain HTML 格式的请求响应消息。
? REST 为 Web 服务中使用的每个资源使用 URI。资源可以是图像文本方法等。
? REST 使用一组动词,如 HTTP 的 GET、POST、PUT、DELETE。
? 与 SOAP UI 相比,REST 易于开发和管理。
? REST 具有轻量级的客户端工具或插件,可以轻松集成到浏览器中。
? REST 服务可以缓存。

回答by IRSHAD

  • REST stands for Representational State Transferwhere as SOAP stands for Simple Object Access Protocol.

  • SOAP defines its own securitywhere as REST inherits security from underlying transport.

  • SOAP doesnot support error handling but REST has built-in error handling.

  • REST is lightweight and does not require XML parsing. REST can be consumed by any client, even a web browser with Ajax and Javascript. REST consumes less bandwidth, it does not require a SOAP header for every message.

    • REST is useful over any protocol which provide a URI. Ignore point 5 for REST as mentioned below in the picture.
  • REST 代表Representational State Transfer,而 SOAP 代表Simple Object Access Protocol

  • SOAP 定义了自己的安全性,而 REST 从底层传输继承了安全性。

  • SOAP 不支持错误处理,但 REST 具有内置的错误处理

  • REST 是轻量级的,不需要XML 解析。任何客户端都可以使用 REST,甚至是带有 Ajax 和 Javascript 的 Web 浏览器。REST 消耗更少的带宽,它不需要每条消息都有一个 SOAP 标头。

    • REST 在提供 URI 的任何协议上都很有用。忽略 REST 的第 5 点,如下图所示。

SOAP vs REST

SOAP 与 REST