JAX-WS – is Java API for the XML-Based Web Services – a standard way to develop a Web- Services in SOAP notation (Simple Object Access Protocol).

Calling of the Web Services is performed via remote procedure calls. For the exchange of information between the client and the Web Service is used SOAP protocol. Message exchange between the client and the server performed through XML- based SOAP messages.

Clients of the JAX-WS Web- Service need a WSDL file to generate executable code that the clients can use to call Web- Service.

JAX-RS – Java API for RESTful Web Services. RESTful Web Services are represented as resources and can be identified by Uniform Resource Identifiers (URI). Remote procedure call in this case is represented a HTTP- request and the necessary data is passed as parameters of the query. Web Services RESTful – more flexible, can use several different MIME- types. Typically used for XML data exchange or JSON (JavaScript Object Notation) data exchange

SOAP REST
SOAP is a protocol. REST is an architectural style.
SOAP can’t use REST because it is a protocol. REST can use SOAP web services because it is a concept and can use any protocol like HTTP, SOAP.
Uses services interfaces to expose the business logic. Uses URI to expose business logic.
JAX-WS is the java API for SOAP web services. JAX-RS is the java API for RESTful web services.
SOAP standards should be strictly followed since it is protocol REST does not define too much standards like SOAP
requires more bandwidth and heavy requires less bandwidth and resource
SOAP defines its own security RESTful web services inherits security measures from the underlying transport.
SOAP permits XML data format only. REST permits different data format such as Plain text, HTML, XML, JSON etc.
SOAP is less preferred REST more preferred than SOAP

When to use SOAP?

  • Exposes operation over a logic – It aligns to enterprises application needs and goals
  • When using SMTP(Simple Mail Transfer Protocol) and JMS
  • It could be used when multiple systems are involved in Distributed Environment I.E. System A -> System B -> System C
  • In a complex system like banks WSDL serves as a agreed agreement for interpreting data over different system
  • SOAP uses two varieties,Synchronous Messaging over HTTP,Asynchronous Messaging over HTTP
    With synchronous messaging, the Requestor makes a request and the transport layer code blocks waiting for a response from the Provider. The Requestor receives the response on the same HTTP connection that the Requestor initially established to send the request. Synchronous exchange is usually easier to implement and requires that the Provider be able to generate a response in a short time, specifically in a time less than the HTTP timeout value(generally 120sec). [A single HTTP Connection is used that itself behaves Synchronously]
    With asynchronous messaging, the Requestor is able to release transport specific resources once the request is acknowledged by the responder, knowing that a response will eventually be received. When the Provider completes the processing of the message it sends a response back to the Requestor over a new HTTP connection. [Here we utilize two HTTP Connections to implement an asynchronous messaging]

    1. first HTTP Connection is used that for sending the Request and receiving an acknowledgement HTTP Response 200/OK
    2. second HTTP Connection is used for receiving the callback and responding HTTP Response 200/OK]
  • SOAP has a option for Service Registry where you can see who is registered for services and who could consume our services
  • Ideal for enterprise application where security(WS-Security), transaction(WS-AT) and reliability(WS-RM) are main concerns

When to use REST?

  • Exposes Resources over data – Simple point to pint communication between two systems System A -> System B
  • While working with synchronous environment
  • Could be used if you want to communicate over Stateless protocol like HTTP/HTTPS
  • It could be consumed by any Client simple by using AJAX and Javascript
  • Rest mostly uses resource as nouns and verbs like delete user, add user, edit user in its URI model
  • REST is purely an HTTP transport based call and you will receive a response say 200 OK. Synchronous messaging. The disadvantage is in order to
    have good scale-ability the architecture should be asynchronous
  • Ideal for mashup where datas are taken from various resources like twitter and less secured data communication