现在我对SOAP和rest式服务之间的区别有了一点了解。
我的问题是什么时候应该使用SOAP,什么时候应该使用RESTful;当谈到性能/速度或请求处理时,哪一个“更好”?
我是第一次在RESTful (Java)实现它,我想知道更多关于它;我以前处理过SOAP。
这是这篇文章的后续问题。
现在我对SOAP和rest式服务之间的区别有了一点了解。
我的问题是什么时候应该使用SOAP,什么时候应该使用RESTful;当谈到性能/速度或请求处理时,哪一个“更好”?
我是第一次在RESTful (Java)实现它,我想知道更多关于它;我以前处理过SOAP。
这是这篇文章的后续问题。
当前回答
REST在大多数情况下更容易使用,也更灵活。与SOAP不同,REST不必使用XML来提供响应。我们可以找到基于rest的Web服务,这些服务以命令分隔值(CSV)、JavaScript对象符号(JSON)和真正简单联合(RSS)格式输出数据。
我们可以以一种易于在应用程序所需的语言中解析的形式获得所需的输出。REST更高效(使用更小的消息格式)、更快,并且在设计理念上更接近其他Web技术。
其他回答
REST几乎总是更快。SOAP的主要优点是它提供了一种机制,可以让服务向客户端描述自己,并宣传它们的存在。
REST轻量级得多,几乎可以使用任何工具实现,从而降低带宽,缩短学习曲线。然而,客户端必须知道要发送什么以及期望发送什么。
通常,当您向外界发布复杂或可能更改的API时,SOAP将更有用。除此之外,REST通常是更好的选择。
休息vs.肥皂
SOAP:
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 a browser. ► REST services are cacheable.
REST没有WSDL (Web描述语言)接口定义。 REST基于HTTP,但SOAP可以基于任何传输协议,如HTTP、FTP、SMTP、JMS等。
REST是一种体系结构。 REST将给出人类可读的结果。 REST是非状态的。 REST服务很容易被缓存。
SOAP是一种协议。它可以运行在JMS、FTP和HTTP之上。
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, and 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 and Delicious. APIs use 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 APIs 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 ColdFusion anyway), 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. Whichever architecture you choose make sure its easy for developers to access it, and well documented.
Freitag, P.(2005)。“REST vs SOAP Web服务”。检索自http://www.petefreitag.com/item/431.cfm, 2010年6月13日