java SOAP 网络服务和 RESTFUL 网络服务的区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7561130/
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
Difference between SOAP webservice and RESTFUL webservice
提问by Kri
I am new to Java.I know that there are two types of web service
我是 Java 新手。我知道有两种类型的 Web 服务
- SOAP Webservice.
- RESTful Webservice.
- SOAP 网络服务。
- RESTful 网络服务。
can any one please tell me what is the basic difference between both of them.And in which situation the SOAP Webservice
is created and in which situation RESTful Webservice
is created.
任何人都可以告诉我它们之间的基本区别是什么。SOAP Webservice
以及在哪种情况下创建和在哪种情况下RESTful Webservice
创建。
Thank You,
谢谢,
采纳答案by andreas
As the first answer allready explains, SOAP Webservices and REST Webservices differ in various points.
正如第一个答案已经解释的那样,SOAP Webservices 和 REST Webservices 在很多方面有所不同。
SOAP:
肥皂:
- you define your interface in a .wsdl file, which describes exactly which input parameters are expected and how the return values will look like
- there are tools to generate the .wsdl files out of java class hirarchies. JAXB for example
- there are also tools to generate java objects/classes as part of eclipse for example (don't know the name in the moment).
- SOAP is very strict. Every request is validatet against the wsdl before processing.
- 您在 .wsdl 文件中定义您的接口,该文件准确描述了预期的输入参数以及返回值的外观
- 有一些工具可以从 Java 类层次结构中生成 .wsdl 文件。以 JAXB 为例
- 例如,还有一些工具可以生成 java 对象/类作为 eclipse 的一部分(目前不知道名称)。
- SOAP 非常严格。每个请求在处理之前都会根据 wsdl 进行验证。
A good but not so easy to start with framework for SOAP WS is Apache CXF
Apache CXF是一个很好但不太容易开始的 SOAP WS 框架
REST (no hands on experience up to now, feel free to correct and improve ;) ):
REST(到目前为止还没有实践经验,请随时纠正和改进;)):
- a way to access a webserver or web application to retrieve data from or send to it.
- it's only negotiated, how it is accessed.
- common is something like this http://server.domain.com/app/type/id=123to retrieve object of type type with id=123
- very intuitive, but no automatic validation of requests.
- ...
- 一种访问网络服务器或网络应用程序以从中检索数据或向其发送数据的方法。
- 它只是协商,它是如何访问的。
- 常见的是这样的http://server.domain.com/app/type/id=123来检索类型为 id=123 的对象
- 非常直观,但没有自动验证请求。
- ...
I am sure, there are several other points I missed. But I think it's a usefull start.
我敢肯定,我还遗漏了其他几点。但我认为这是一个有用的开始。
回答by Bhaskar
At a very basic level , SOAP is a messaging protocol , REST is a design philosophy , not a protocol. When you base a WebService on a SOAP protocol , you basically comply with SOAP rules of creating a Service Request , posting the request to server , receiving the request at server , processing the request and returning the results as a SOAP message.SOAP does not talk about the exact manner in which client benefits from the service, nor about how to design the client itself ( apart from the message it is posting ), it only tells how a message from client can be sent to service and back.
在非常基本的层面上,SOAP 是一种消息传递协议,REST 是一种设计理念,而不是一种协议。当您基于 SOAP 协议构建 WebService 时,您基本上遵守 SOAP 规则,即创建服务请求、将请求发布到服务器、在服务器接收请求、处理请求并将结果作为 SOAP 消息返回。SOAP 不会说话。关于客户端从服务中受益的确切方式,也没有关于如何设计客户端本身(除了它发布的消息),它只说明如何将来自客户端的消息发送到服务并返回。
REST is short for REpresentational State Transfer. It does not specify the rules to create a message and post it to server. You can do this by simple HTTP protocol. What REST specifies is the manner in which client and server manage their states so that they become useful to the client -server communication. Here , you are more focussed on designing the states of clients and servers rather than the messages they are exchanging.
REST 是 REpresentational State Transfer 的缩写。它没有指定创建消息并将其发布到服务器的规则。您可以通过简单的 HTTP 协议来做到这一点。REST 指定的是客户端和服务器管理其状态的方式,以便它们对客户端 - 服务器通信有用。在这里,您更专注于设计客户端和服务器的状态,而不是它们交换的消息。