WEB SERVICES & SOAP VS. REST
✵ A web service can be known as a self contained, modular and dynamic medium that is mainly used to communicate between client and server applications or software over the web.
✵ It is basically a XML-based information exchange system that is designed with the intention of performing specific tasks over the Internet or private (intranet) networks.
✵ Use of open protocols and standards such as TCP/IP, HTTP, XML, WSDL, Java and HTML has made this interoperable.
✵ Web services in cloud computing can be discovered over the network using simple find mechanism and can also be invoked accordingly.
✵ Once invoked, web services must be able to provide clients with functionalities.
How Web Services Work
✵ Web services use;
➢ XML — To tag data
➢ WSDL — To describe service availability
➢ SOAP — To transfer messages
✵ XML that stands for Extensible markup language (General-purpose data document format), is known as the main component of a web service design.
✵ XML caters a common platform for applications implemented using various programming languages to communicate with each other.
✵ The client is capable of invoking multiple web service calls to a server in which the actual we service is hosted, via requests. These requests are made via Remote Procedure Calls.
Remote Procedure Calls
☛ Define the functions that will be available remotely.
☛ These functions form the interface of the server.
Ex: int getCustomerID(int customer name)
🔹 RPC proxy/stub: code that goes on the client side, so the client can use the function.
🔹 RPC skeleton (outdated): the empty function that goes on the server side ready for the developer to complete.
Benefits of Web Services
🟢 Communication cost is low
🟢 A Standardized Protocol which can be understood by anyone
🟢 Exposing existing Functionality on the network
🟢 Ease of use
Web Service Characteristics
🔵 Synchronous or Asynchronous functionality
🔵 Supports Remote Procedure Calls(RPCs)
🔵 Loosely Coupled
🔵 Supports Document Exchange
Web Service Architecture
✵ The web service architecture has 3 major components.
1. Service Provider
Web service is created by the Service provider and makes it available on the internet for whoever wants to utilize it.
2. Service Requestor
The client application which is needed to be contacted by a web service through starting a network connection and sending an XML request.
3. Service Registry
It is a directory of services that is centralized logically with the purpose of giving opportunity for the developers to publish new services or find existing ones.
Types of Web Services
There are 2 main types of web services.
- SOAP web services.
- RESTful web services.
SOAP Web Services (Simple Object Access Protocol)
✽ SOAP (Simple Object Access Protocol) is a communication protocol which is used in web services in order to send the XML data between applications over normal HTTP.
✽ IT is a strictly defined XML based message format.
✽ Specifically focused on passes RPC calls across the internet.
◦ defines how to marshall a function name and parameters into an XML message.
◦ Sending the message to the server then ‘does’ the RPC.
✽ The data which is transmitted from the web service to the application is known as a SOAP message. The SOAP is basically an XML document.
✽ The client application that is used to call the web service can be written in any programming language as the document is written in XML. There SOAP is language independent.
Advantages of SOAP
🟥 Defines its own WS security
🟥 Light-weighted protocol
🟥 Simple, extensible and platform independent
🟥 Let you get around firewalls.
SOAP Message Structure
A simple soap message contains following elements.
♦️ The Envelope element — It is the root element that encapsulates all the mandatory details of the SOAP message. It specifies the start and the end of a SOAP message.
♦️ The header element — If there is a header element inside envelope element, Only one header element should be there. Routing data and authentication information are included in header element and it comes as the first child of the Envelope.
♦️ The body element — Actual message is residing inside body. The body element consists of the web method definitions along with any parameter information if required.
♦️ The Fault element (Optional)
Disadvantages of SOAP
🟨 WSDL Dependent
🟨 Supports only XML
🟨 Tightly coupled
✽ REST (Representational State Transfer) defines a set of constraints that define how a server is created/setup. (i.e. a RESTful Server)
✽ It expands the traditional GET and POST types
➢ GET: read-only and safe.
➢ POST: multiple requests can cause different results.
➢ PUT: — multiple requests will result in the same outcome.
➢ DELETE: — multiple requests will result in the same outcome.
RESTful Web Services
✽ Restful web services are built on REST architecture based on HTTP methods.
✽ Restful web services are scalable, maintainable, light-weighted and they define a Uniform Resource Identifier (URI), set of HTTP methods and provide resource representation such as JSON .
Key Elements of Restful Implementation
- Resources — The first key element
- Request Verbs — Indicate what to be done with the resource
- Request Headers — May define response types which are required or the details regarding authorization.
- Request Body — Information about the resource that should be added to the server.
- Response Body — Main body of the response
- Response Status codes — The general codes that comes back with web server responses.
Advantages of RESTful
🟥 Supports multiple languages and environments
🟥 Simplify application design
RESTful Principles and Constraints
- RESTFul Client-Server — The client and server application need to be able to evolve independently.
- Stateless — Client must make sure that all the required information is provided correctly to the server. The server should not maintain any information between requests from the client.
- Cache — Can be implemented either on the server or the client side. Caching should be applied to resources when possible, and these resources MUST declare themselves cacheable.
- Layered System — The middleware layer where all the business logic is set up. A client is incapable of telling specifically whether it is connected directly to the end server or an intermediary along the way.
- Interface/Uniform Contract — The underlying method of how RESTful web services are working. RESTful usually works on the HTTP web layer.
- Code-on-Demand — This is one of the optional constraints where you are allowed to
return executable codeto support a part of your application.
Key Differences between SOAP and REST
What are Web Services? Architecture, Types, Example
Web service is a standardized medium to propagate communication between the client and server applications on the World…
SOAP Web Services Tutorial: What is SOAP Protocol? EXAMPLE
SOAP is an XML-based protocol for accessing web services over HTTP. It has some specification which could be used…