`

WebService: SOAP VS. RESTFul

阅读更多
Understanding SOAP and REST Basics And Differences
January 8, 2013 by John Mueller

一、背景知识


1、什么是 WebService ?

-
   Web 上的 Service。

   谁的 Service? 对象不是人。是机器。

   人通过Web获取的信息都是利于人阅读的。而 WebService 提供的信息是利于机器阅读的。

   所以 WebService 的全名是: Application Web Service 。面向应用的web服务。

-
   为什么需要 WebService?

   可以提供系统与系统间的通信。可以构建复杂的分布式系统。


   WebService 只是一个抽象的概念。只要能够提供面向应用的web服务,都可以成为 WebService。
   它可以用 Java 实现,可以用 .NET 实现。
  
   本文只针对 Java 实现。


二、SOAP VS. REST

Simple Object Access Protocol (SOAP) and Representational State Transfer (REST) are two answers to the same question: how to access Web services. The choice initially may seem easy, but at times it can be surprisingly difficult.
实现 WebService 的方式中, SOAP 和 REST 是其中两种。选择哪一种乍看起来简单,但是多数情况下,其实相当困难。


SOAP is a standards-based Web services access protocol that has been around for a while and enjoys all of the benefits of long-term use. Originally developed by Microsoft, SOAP really isn’t as simple as the acronym would suggest.
SOAP是基于规范的一种 WebService 实现协议。(注意:这里的协议不属于网络七层协议,而是用户用于数据传输而自定义的协议。SOAP 是所有自定义协议的统称。)SOAP已经使用了一段时间,带来了很大方便,并有初具规模的长期服务。SOAP 最初由 Microsoft 开发。SOAP 并不像它简称上写的那样简单。


__________________________________________________________________________________

关于 RESTful :
-
    Representational State Transfer
   
    which state ? The state of object.

-

    Representational State of Object Transfer
   
    对象的表示化状态-传输。 (表示成什么呢?文本)

    比较专业的翻译: 具象状态传输 (对象的状态具文本象,传输)

    把如此专业的概念说的如此抽象。不就是字符串么?不仅仅是。
    字符串只是对象的一种象。对象的象还可以是二进制字节流。
    但,RESTful 目前只支持字符串,貌似。
-  
   
_________________________________________________________________________________



三、The Difference between SOAP vs REST APIs

REST is the newcomer to the block. It seeks to fix the problems with SOAP and provide a truly simple method of accessing Web services. However, sometimes SOAP is actually easier to use; sometimes REST has problems of its own. Both techniques have issues to consider when deciding which protocol to use.
REST 是新来的。它寻求解决 SOAP 的不足和问题,提供了一种够简单的 WebService 的实现方案,然而,特定情况下 SOAP 使用起来更简单。 REST 也有自己的不足。当选择时,它们各自的问题和不足都要考虑到。

Before I go any further, it’s important to clarify that while both SOAP and REST share similarities over the HTTP protocol, SOAP is a more rigid set of messaging patterns than REST. The rules in SOAP are important because without these rules, you can’t achieve any level of standardization. REST as an architecture style does not require processing and is naturally more flexible. Both SOAP and REST rely on well-established rules that everyone has agreed to abide by in the interest of exchanging information.
在继续讨论之前,首先声明:SOAP 是基于协议的。它在交换数据时必须同时携带定义数据的协议数据。虽然 SOAP 和 REST 在使用 HTTP 协议上有相同点,但是 SOAP 是硬性要求传递数据解析的格式。如果这些格式缺失或被省略,SOAP 无法工作。而 REST 则是一种构建模式形式,不硬性要求信息的解析处理,所以原生更灵活。当然,两者都需要知道数据的格式才可以数据的交换。



A Quick Overview of SOAP
SOAP relies exclusively on XML to provide messaging services. Microsoft originally developed SOAP to take the place of older technologies that don’t work well on the Internet such as the Distributed Component Object Model (DCOM) and Common Object Request Broker Architecture (CORBA). These technologies fail because they rely on binary messaging; the XML messaging that SOAP employs works better over the Internet.

After an initial release, Microsoft submitted SOAP to the Internet Engineering Task Force (IETF) where it was standardized. SOAP is designed to support expansion, so it has all sorts of other acronyms and abbreviations associated with it, such as WS-Addressing, WS-Policy, WS-Security, WS-Federation, WS-ReliableMessaging, WS-Coordination, WS-AtomicTransaction, and WS-RemotePortlets. In fact, you can find a whole laundry list of these standards on Web Services Standards.

The point is that SOAP is highly extensible, but you only use the pieces you need for a particular task. For example, when using a public Web service that’s freely available to everyone, you really don’t have much need for WS-Security.

The XML used to make requests and receive responses in SOAP can become extremely complex. In some programming languages, you need to build those requests manually, which becomes problematic because SOAP is intolerant of errors. However, other languages can use shortcuts that SOAP provides; that can help you reduce the effort required to create the request and to parse the response. In fact, when working with .NET languages, you never even see the XML.

Part of the magic is the Web Services Description Language (WSDL). This is another file that’s associated with SOAP. It provides a definition of how the Web service works, so that when you create a reference to it, the IDE can completely automate the process. So, the difficulty of using SOAP depends to a large degree on the language you use.

One of the most important SOAP features is built-in error handling. If there’s a problem with your request, the response contains error information that you can use to fix the problem. Given that you might not own the Web service, this particular feature is extremely important; otherwise you would be left guessing as to why things didn’t work. The error reporting even provides standardized codes so that it’s possible to automate some error handling tasks in your code.

An interesting SOAP feature is that you don’t necessarily have to use it with the HyperText Transfer Protocol (HTTP) transport. There’s an actual specification for using SOAP over Simple Mail Transfer Protocol (SMTP) and there isn’t any reason you can’t use it over other transports. In fact, developers in some languages, such as Python and PHP, are doing just that.



A Quick Overview of REST
Many developers found SOAP cumbersome and hard to use. For example, working with SOAP in JavaScript means writing a ton of code to perform extremely simple tasks because you must create the required XML structure absolutely every time.

REST provides a lighter weight alternative. Instead of using XML to make a request, REST relies on a simple URL in many cases. In some situations you must provide additional information in special ways, but most Web services using REST rely exclusively on obtaining the needed information using the URL approach. REST can use four different HTTP 1.1 verbs (GET, POST, PUT, and DELETE) to perform tasks.

Unlike SOAP, REST doesn’t have to use XML to provide the response. You can find REST-based Web services that output the data in Command Separated Value (CSV), JavaScript Object Notation (JSON) and Really Simple Syndication (RSS). The point is that you can obtain the output you need in a form that’s easy to parse within the language you need for your application.

As an example of working with REST, you could create a URL for Weather Underground. The API’s documentation page shows an example URL of http://api.wunderground.com/api/Your_Key/conditions/q/CA/San_Francisco.json. The information you receive in return is a JSON formatted document containing the weather for San Francisco. You can use your browser to interact with the Web service, which makes it a lot easier to create the right URL and verify the output you need to parse with your application.



Deciding Between SOAP and REST
Before you spend hours fretting over the choice between SOAP and REST, consider that some Web services support one and some the other. Unless you plan to create your own Web service, the decision of which protocol to use may already be made for you. Extremely few Web services, such as Amazon, support both. The focus of your decision often centers on which Web service best meets your needs, rather than which protocol to use.



Soap Vs Rest
SOAP is definitely the heavyweight choice for Web service access. It provides the following advantages when compared to REST:

- Language, platform, and transport independent (REST requires use of HTTP)
- Works well in distributed enterprise environments (REST assumes direct point-to-point communication)
   SOAP 可以传递序列化的对象,二进制数据流。该特点在分布式环境中发挥的很好。
   REST 目前的支持的数据传递格式为字符文本。故只能是点对点传输。

- Standardized
- Provides significant pre-build extensibility in the form of the WS* standards
- Built-in error handling
- Automation when used with certain language products



REST is easier to use for the most part and is more flexible. It has the following advantages when compared to SOAP:

- No expensive tools require to interact with the Web service
- Smaller learning curve
- Efficient (SOAP uses XML for all messages, REST can use smaller message formats)
- Fast (no extensive processing required)
- Closer to other Web technologies in design philosophy








-
转载请注明,
原文出处:http://lixh1986.iteye.com/blog/2346064




-


Java Web Service 20 问





分享到:
评论

相关推荐

    SOAP webserivce 和 RESTful webservice 对比及区别

    SOAP Web服务和RESTful Web服务是两种常见的Web服务交互方式,它们在设计理念、协议复杂度、数据格式和操作方式等方面存在显著的区别。 首先,SOAP(简单对象访问协议)是一种基于XML的协议,它允许不同系统之间的...

    SOAP webserivce 和 RESTful webservice 对比及区别.pdf

    SOAP webserivce 和 RESTful webservice 对比及区别.pdfSOAP webserivce 和 RESTful webservice 对比及区别.pdf

    在同一个系统里用cxf 实现SOAP 协议和RESTful风格 两种类型的webservice接口

    在IT行业中,Web服务是应用程序之间进行通信的一种标准方法,其中两种主要的接口类型是SOAP(Simple Object Access Protocol)和RESTful(Representational State Transfer)。本篇将详细讲解如何使用Apache CXF框架...

    基于 cxf 2.7.5 开发的 webservice [soap restful]

    【标题】基于CXF 2.7.5开发的WebService:SOAP与RESTful详解 【描述】本项目是使用Apache CXF 2.7.5版本实现的WebService服务,包括了SOAP和RESTful两种常见的Web服务接口。Apache CXF是一个开源的Java框架,它为...

    webservice :spring 3+cxf3.4服务方,AXIS1.4请示方调用

    其中,Spring框架与Apache CXF是实现RESTful或SOAP风格的Web服务的常用工具之一。而Axis 1.4则常作为客户端来调用这些服务。本文将详细介绍如何使用Spring 3 + CXF 3.4搭建服务端,并通过Axis 1.4进行调用。 #### ...

    什么是REST,符合REST的API叫RESTful 两种SOA接口实现:SOAP(WebService) vs REST

    文件`rest(一种软件架构风格)_百度百科.url`和`SOA接口的两种常用实现比较:SOAP(WebService) vs REST(GET,POST).url`分别指向了关于REST和SOAP/REST比较的参考资料,它们可以进一步深入理解这两种接口实现的区别...

    REST WebService与SOAP WebService的比较.docx

    **REST (Representational State Transfer) WebService 和 SOAP (Simple Object Access Protocol) WebService 是两种不同的 Web Service 技术,它们在 SOA(Service-Oriented Architecture,面向服务架构)领域中...

    webservice测试调用工具.rar

    7. **多协议支持**:除了基础的SOAP协议,可能还支持RESTful WebService,使用JSON等轻量级数据格式进行通信。 8. **易用性**:界面友好,操作简单,即便是非专业开发者也能快速上手。 在使用WebserviceStudio20...

    WebService源码和笔记.zip

    7. **RESTful服务对比**:对比RESTful API与传统的SOAP WebService,讨论它们的优缺点以及适用场景。 8. **实际应用案例**:通过具体的案例分析,展示WebService在实际业务中的应用,如企业系统间的集成、数据交换...

    专题资料(2021-2022年)webservice项目搭建教程.doc

    - 它不仅支持SOAP 1.1和SOAP 1.2,还兼容RESTful WebService,并且支持Spring框架以及JSON等技术。 - Axis2可以通过插件形式集成到MyEclipse中,实现快速开发和服务部署。 #### 二、MyEclipse环境配置 接下来...

    基于Jdeveloper进行WebService开发及部署.docx

    1. **RESTful API**:除了传统的SOAP协议,还可以采用RESTful风格来实现WebService,提供更加灵活和简洁的接口。 2. **异步处理**:对于耗时较长的操作,可以采用异步处理机制,提高系统的整体性能。 3. **消息队列*...

    java+soap+webservice 调用模拟

    通过阅读提供的"java-soap-webservice"文档,你可以进一步了解具体的实现步骤,包括如何设置项目、配置JAX-WS、生成客户端代码、编写调用服务的代码,以及如何解析响应。实践中,不断动手操作和调试是掌握这一技术的...

    Java WebService 简单实例 方式一(生成类文件方式)

    随着技术的发展,尽管 RESTful API 的流行度越来越高,但 SOAP 风格的 WebService 仍然在某些场景下有着不可替代的作用。 希望本文能够帮助读者更好地理解和掌握 Java WebService 的基本概念与开发流程。

    Webservice接口调试工具.zip.zip

    Web服务(WebService)是一种基于标准协议的,允许不同系统间进行通信和数据交换的技术。它通过定义一套统一的接口标准,使得应用程序可以无视操作系统、编程语言的差异,进行跨平台的交互。本压缩包文件...

    java调用webservice(20211103125800).rar

    在理解Java调用WebService之前,首先要了解SOAP(Simple Object Access Protocol)和WSDL(Web Services Description Language)。SOAP是一种基于XML的消息协议,用于在Web上交换结构化和类型化的信息。WSDL则是一个...

    Android调用Java WebService的实现方法.zip

    4. **构建请求**:根据WebService的要求,构造SOAP请求或者RESTful请求。如果是SOAP,你需要设置请求头、SOAPAction以及XML消息体;如果是RESTful,可能只需要设置URL和HTTP方法,如GET或POST,并附带JSON或XML数据...

    SOAP调用webservice例子

    **SOAP与RESTful API的对比** - SOAP是基于XML的,而RESTful API通常是基于JSON,后者更轻量级,解析速度更快。 - SOAP提供了一套完整的规范,包括错误处理、事务支持等,而RESTful API更灵活,但需要自定义这些功能...

    Android通过WebService连接SQLServer浅析.pdf

    2. 引用 WebService:在 Android 应用程序中引用 WebService,通过 SOAP 或 RESTful API 与 WebService 进行交互。 3. 实现数据交互:Android 应用程序通过 WebService 与 SQL Server 进行数据交互,实现数据的实时...

    文档(DocService)WebService接口使用说明.rar

    1. **接口规范**:详细描述了接口的调用格式,如SOAP(Simple Object Access Protocol)或RESTful API,以及使用的HTTP方法(GET、POST等)。 2. **服务地址**:提供Web Service的URL,开发者需要将此地址与自己的...

Global site tag (gtag.js) - Google Analytics