最新消息:

webservice笔记2—— REST 与 SOAP

JAVA 大步 1116浏览 0评论

webserivce常见的两种:REST  和 SOAP

   # REST: REpresentationl State Transfer (Roy Fielding's dissertation, 2000)
   # SOAP: once Simple Object Access Protocol, but no longer an acronym
     ## In effect, the next generation of XML-RPC (late 1990s)
   # REST is really a style, even a state of mind
     ## The JSP-based 'predictions' service would be considered REST-style or RESTful
   # SOAP is at once a messaging protocol and an XML dialect (W3C).
   # Differences in the client/service conversation:
                    HTTP GET, POST, PUT, or DELETE
     REST: client ----------------------------------> service
           client <---------------------------------- service
                    XML, JSON, plaintext,... document
                  HTTP POST of SOAP request document
     SOAP: client ----------------------------------> service
           client <---------------------------------- service
              SOAP (maybe JSON) document
   # Rails framework has influenced the RESTful style.
     ## Amazon supports both REST-style and SOAP-based services.

REST as an API for web services

    ## 一个"resource"就是一条信息条目,如 Acme公司的产品列表。
       ###个资源被放置在某些网络主机上 e.g., www.acme.com.
       ### 一个resource 有“state”(状态),并且这个状态是可以一直改变的。 (e.g.产品列表的增加).
       ###各种可能呈现方式:  XML或者JSON 文档, 图像的幻灯片等
    ## HTTP对resource的支持
       ### URIs (Uniform Resource Identifiers) name resources, e.g., /acme/products.
           URLs and URNs (N for 'name') are URI subtypes.
       ### Methods ("verbs") describe operations, in particular the CRUD operations:
           POST   /acme/products  ## Create a new Acme product
  GET    /acme/products  ## Read a list of Acme products
  PUT    /acme/product   ## Update a specified Acme product
  DELETE /acme/product   ## Delete a specified Acme product
       ### MIME types specify (desired and actual) HTTP payloads (e.g., text/xml, application/json)
       ### Status codes (SCs) returned to client to signal how the request fared.
           Common examples are:
             200 == OK
    404 == Not Found
    505 == Server Error

REST中常见的模式

             HTTP verb/noun
     client ----------------> RESTful service
             GET  /products
    POST /orders
    ...
              HTTP SC + body
     client <---------------- RESTful service
               200 (OK) XML
      200 (OK) JSON
      200 (OK) Plaintext
      ...
    # Challenges in REST are mostly on the client sideREST中任务主要是在客户端
      ## 客户端必须解析xml文档,从其中提取内容
         ### 客户端必须处理特殊的 XML响应

  基于SOAP service的常见模式

  # Client/service interaction:
             POSTed SOAP document
     client ----------------------> server
                 HTTP request
                 SOAP document
     client <---------------------- server
                 HTTP response
  # Minuses
    ## 比REST要复杂,需要其他的软件库:
                           SOAP library
Java List<Product> ------------> XML ----> service
        Java List<Prices>  <------------ XML <---- service
                            SOAP library
不需要客户端去解析返回的xml(json),因为底层的库已经实现了解析功能
有很多工具去为每个service生成基本的客户端代码。

 

来自为知笔记(Wiz)

 

转载请注明:大步's Blog » webservice笔记2—— REST 与 SOAP

SiteMap