What are Web Services?
If you are a Web Developer or a beginner learning about Web Technologies, it is essential to learn about Web Services. So without further ado, let’s dive into the topic of Web Services.
Internet and the World Wide Web
The Internet is a worldwide network of computers, through which one computer can send information to another computer. It uses the TCP/IP protocol to link devices together. Whether we chat with friends, watch a YouTube video, or play games, we constantly send and receive information through the internet.
On the other hand, World Wide Web (WWW) is the collection of websites that can be accessible with the help of the internet. It is the online content that we see, which is formatted in HTML. Its resources are transferred via the Hypertext Transfer Protocol(HTTP). The resources of WWW are identified by URL(Uniform Resource Locator) and is accessed using the Internet. With the help of the different web browsers, we can search and click on various resources on the WWW.
Now that we understand the basic concepts of the Internet and WWW, let’s move on to Web services.
Web services are based on distributed computing technology. It provides a standardized medium for interoperating different applications using open standards such as SOAP and WSDL. A key feature of Web Services is that applications can be written in various languages and can still communicate by exchanging data between clients and servers.
According to the W3C definition,
A Web service is a software system designed to support interoperable machine-to-machine interaction over a network.
The following are the basic features of a Web Service.
- Interoperability is a fundamental characteristic of Web Services. Web services allow various applications to exchange information with each other irrespective of the platform and programming language. For example, a .NET Web Service Client application written in Visual Basic can invoke a Web Server on Sun Microsystems computer running Solaris.
- Web services use XML or Extensible Markup Language for the exchange of data between Client and Server.
- Web Services are Loosely Coupled. A Service Requestor only needs to know about the interface of Web Service and not its actual implementation.
- Web Services support RPC or Remote Procedure Calls. Client Applications can invoke methods on remote objects using an XML-based protocol.
The three major components of a Web Service are:
SOAP: SOAP or Simple Object Access Protocol is a messaging protocol for accessing Web Services. We will discuss more SOAP in the later part of this blog.
WSDL: WSDL or Web Services Description Language is simply an XML-based description language containing information about a Web Service. It defines how to access a Web Service and defines the functionalities of a Web Service.
UDDI: UDDI or Universal Description, Discovery, and Integration is a specification for creating a registry service to list organizations and their Web services.
How does Web Services work?
Web service uses
- XML tag for tagging the data
- SOAP for sending the XML data
- WSDL to know the functionalities
There is a client and a server on the Web.
- XML is the heart of Web Services and is the language by which the Client and the Server exchange data. XML/Extensible Markup Language is very similar to HTML, which defines a set of rules for encoding documents. It is used to store and transport data.
- A client invokes Web Services by sending a request to the server via XML. These requests are made through RPCs (Remote Procedure Calls).
- The server which hosts the Web Service then sends back an XML response.
Web Service Architecture
The Web Service Architecture consists of three distinct roles -
- Service Provider: A Service Provider is a platform that creates the Web Service and makes it available to the Client applications.
- Service Requester: A Service Requestor is the Client application.
- Service Registry: A Service Registry is based on the UDDI specification and contains information about the services provided by Service Provider.
The interactions between the roles consist of three operations:
- Publish: The Service Provider publishes its service description in the Service Registry.
- Find: The Service Requester finds the description of service in the Service Registry.
- Bind: The Service Requester then binds with the Service Provider using the description to interact with the Web Service.
Why do we need web services?
- Today web applications are developed using various programming languages like .NET, Node.js, etc. Therefore to make communication possible between two applications, Web Services comes into the picture.
- Another advantage is that Web Services can be implemented with a low-cost internet connection as they employ the SOAP over HTTP.
- Additionally, a single web server can be used by many client applications making make it reusable.
Types of Web Services
There are two types of Web Services - SOAP and RESTful Web Services.
SOAP and REST are two completely different approaches when it comes to online data transmission. Let us understand them one by one.
SOAP (Simple Object Access Protocol) is a messaging protocol specification for accessing Web services. It is XML-based, making it platform and language independent.
1. SOAP has tight security as it defines its security known as WS(Web Standards) security. WS security is a set of guidelines for regulating authentication for SOAP messaging.
2. SOAP is a program, platform, and transport-independent protocol. Developers can call processes running on different Operating Systems.
3. SOAP messages are exchanged via HTTP, which is the standard web protocol.
A SOAP message is essentially an XML document consisting of an envelope element. The envelope element consists of a Header and Body element.
The Envelope or the root element in the SOAP message contains the information about the message.
- The Header contains information related to the routing information but is not a compulsory element in SOAP.
- The Body contains the actual message for the recipient of the message.
- The Fault is an optional element of the Body which gives information about any errors that might have occurred during message processing.
REST(Representational State Transfer) is an architectural style that defines a set of guidelines to build a scalable system on the web.
Web Services based on REST Architecture are known as RESTful web services.
- In REST architecture, data and functionality are considered resources.
- These resources are accessed by using URIs(Uniform Resource Identifiers).
- REST uses various various representation to represent a resource like HTML,plain text,JSON, XML PDF ,etc.
- Resources are manipulated using a set of 4 HTTP methods.
- GET (Read)
- POST (Create)
- PUT (Update)
- DELETE (Delete)
- Every interaction with REST is stateless, as the server does not store any state about the client session on the server-side.
SOAP vs REST
The following are the significant differences between SOAP and REST:
Frequently Asked Questions
Q1) What is a Web Service?
Ans: A Web service is a software system designed to support interoperable machine-to-machine interaction over a network.
Q2) What are the components of Web Service?
Ans: The three main components of Web Service are:
- SOAP (Simple Object Access Protocol)
- UDDI (Universal Description, Discovery, and Integration)
- WSDL (Web Services Description Language)
Q3) What is XML-RPC?
Ans: XML-RPC is a protocol used for making remote procedure calls across a network. It makes procedure calls using XML as an encoder and HTTP as the transport medium.
Q4) What is the difference between Web Service and API?
Ans: Web Services and API are two terms used interchangeably but are different from each other.
API stands for Application Programming Interface. It is a software interface that acts as a bridge between two applications and helps them communicate.
On the other hand, a Web Service is a software system that provides a standardized medium for interoperating between different applications.
In fact, APIs are a subset of Web Services. Every Web Service is an API, but the opposite is not valid.
In this blog, we learned about Web Services, their features, components, and underlying architecture. We also learned about the two types of Web Services - SOAP and REST.
Happy Learning Ninja!