简体   繁体   中英

Comparison between SOAP/WSDL/XSD and REST approaches

Until now, I've been working exclusively with SOAP Web Services written in Java. To build a new SOAP WS my approach was like this (main steps):

  • define the WSDL/XML schema (xsd) contract
  • generate JAXB classes from XSD and JAVA interface from WSDL
  • implement the generated interface ie the Web Service
  • deploy the Web Service

Also, to build a Java client for this WS I reuse the WSDL and XSD and wrap it in a single JAR with some helpers to call the WS.

So a "Top down" approach. I was using Apache CXF to build and deploy my WS, especially its WSDL2Java tool.

Today, I need to create a RESTful WS which consumes and produces only JSON data. I've done some research and the tool I will probably be using are Jersey or Apache CXF (most likely Jersey). But regardless that, I don't know what must be my approach for this.

Can it be the same as for a SOAP Web Service? I know there is WADL, but can it be used as a WSDL in my case, espacially given that my goal is to use JSON? I would like my POJOs also be generated from some schema, something like JAXB classes for a SOAP WS, for a better maintenance.

Am I completely off topic about this? I know REST and SOAP shouldn't be seen the same way.

Could you help me to understand? Thanks

You can basically do the same process with REST too, with small but crucial differences:

Step 1 : Define what resources should be available, and define schema for XML/Json/whatever for the representations of these resources. This is called a Mime Type in HTTP parlance. It can contain the Schema for the data, but more importantly descriptions of what kind of links are present and what they mean. (Link to next result list, link to owner, link to details, etc.) Describe semantics here in addition to a technical description of which fields are required/optional etc.

Step 2 : Generate classes, if you wish. I found a project that says it can do that for json: https://github.com/joelittlejohn/jsonschema2pojo , I'm sure there are others.

Step 3 : Implement.

Step 4 : Deploy.

Note : There is no WSDL, or "Service class" that equals that of SOAP. This is because REST includes navigational and semantic information (if it's done right). There is no need to describe where a service is or how to access it, since all clients can get there via Links, and all clients know GET. This actually makes implementing clients also different than with SOAP.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM