0% found this document useful (0 votes)
3 views17 pages

API-MS Unit 4

Web services are standardized methods for message exchange between client and server applications over the internet, enabling interoperability across different programming languages and platforms. They utilize XML for data representation and can be accessed via protocols like SOAP, WSDL, and UDDI. Service-Oriented Architecture (SOA) enhances web services by allowing for reusable, loosely coupled services that can be combined to create applications.

Uploaded by

Ps Naveen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views17 pages

API-MS Unit 4

Web services are standardized methods for message exchange between client and server applications over the internet, enabling interoperability across different programming languages and platforms. They utilize XML for data representation and can be accessed via protocols like SOAP, WSDL, and UDDI. Service-Oriented Architecture (SOA) enhances web services by allowing for reusable, loosely coupled services that can be combined to create applications.

Uploaded by

Ps Naveen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

UNIT-IV

1) What are Web Services?


What are Web Services?

The Internet is the worldwide connectivity of hundreds of thousands of computers of various types
that belong to multiple networks. On the World Wide Web, a web service is a standardized method
for propagating messages between client and server applications. A web service is a software module
that is intended to carry out a specific set of functions. Web services in cloud computing can be
found and invoked over the network.
The web service would be able to deliver functionality to the client that invoked the web service.

A web service is a set of open protocols and standards that allow data to be exchanged between
different applications or systems. Web services can be used by software programs written in a variety
of programming languages and running on a variety of platforms to exchange data via computer
networks such as the Internet in a similar way to inter-process communication on a single computer.

Any software, application, or cloud technology that uses standardized web protocols (HTTP or HTTPS)
to connect, interoperate, and exchange data messages – commonly XML (Extensible Markup
Language) – across the internet is considered a web service.
Web services have the advantage of allowing programs developed in different languages to connect
with one another by exchanging data over a web service between clients and servers. A client
invokes a web service by submitting an XML request, which the service responds with an XML
response.

Functions of Web Services

 It’s possible to access it via the internet or intranet networks.

 XML messaging protocol that is standardized.

 Operating system or programming language independent.

 Using the XML standard, it is self-describing.

 A simple location approach can be used to locate it.

Components of Web Service

XML and HTTP is the most fundamental web services platform. The following components are used
by all typical web services:

SOAP (Simple Object Access Protocol)

SOAP stands for “Simple Object Access Protocol.” It is a transport-independent messaging protocol.
SOAP is built on sending XML data in the form of SOAP Messages. A document known as an XML
document is attached to each message. Only the structure of the XML document, not the content,
follows a pattern. The best thing about Web services and SOAP is that everything is sent through
HTTP, the standard web protocol.
A root element known as the element is required in every SOAP document. In an XML document, the
root element is the first element. The “envelope” is separated into two halves. The header comes
first, followed by the body. The routing data, or information that directs the XML document to which
client it should be sent to, is contained in the header. The real message will be in the body.

UDDI (Universal Description, Discovery, and Integration)

UDDI is a standard for specifying, publishing and discovering a service provider’s online services. It
provides a specification that aids in the hosting of data via web services. UDDI provides a repository
where WSDL files can be hosted so that a client application can discover a WSDL file to learn about
the various actions that a web service offers. As a result, the client application will have full access to
the UDDI, which serves as a database for all WSDL files.
The UDDI registry will hold the required information for the online service, just like a telephone
directory has the name, address, and phone number of a certain individual. So that a client
application may figure out where it is.

WSDL (Web Services Description Language)

If a web service can’t be found, it can’t be used. The client invoking the web service should be aware
of the location of the web service. Second, the client application must understand what the web
service does in order to invoke the correct web service. The WSDL, or Web services description
language, is used to accomplish this. The WSDL file is another XML-based file that explains what the
web service does to the client application. The client application will be able to understand where
the web service is located and how to use it by using the WSDL document.

How Does Web Service Work?

The diagram depicts a very simplified version of how a web service would function. The client would
use requests to send a sequence of web service calls to a server that would host the actual web
service.

Remote procedure calls are what are used to make these requests. Calls to methods hosted by the
relevant web service are known as Remote Procedure Calls (RPC). Example: Flipkart offers a web
service that displays prices for items offered on Flipkart.com. The front end or presentation layer can
be written in .Net or Java, but the web service can be communicated using either programming
language.
The data that is exchanged between the client and the server, which is XML, is the most important
part of a web service design. XML (Extensible markup language) is a simple intermediate language
that is understood by various programming languages. It is a counterpart to HTML. As a result, when
programs communicate with one another, they do so using XML. This creates a common platform for
applications written in different programming languages to communicate with one another.
For transmitting XML data between applications, web services employ SOAP (Simple Object Access
Protocol). The data is sent using standard HTTP. A SOAP message is data that is sent from the web
service to the application. An XML document is all that is contained in a SOAP message. The client
application that calls the web service can be created in any programming language because the
content is written in XML.

Features/Characteristics Of Web Service

Web services have the following features:

(a) XML Based: The information representation and record transportation layers of a web service
employ XML. There is no need for networking, operating system, or platform binding when using
XML. At the middle level, web offering-based applications are highly interoperable.

(b) Loosely Coupled: A customer of an internet service provider isn’t necessarily directly linked to
that service provider. The user interface for a web service provider can change over time without
impacting the user’s ability to interact with the service provider. A strongly coupled system means
that the patron’s and server’s decisions are inextricably linked, indicating that if one interface
changes, the other should be updated as well.
A loosely connected architecture makes software systems more manageable and allows for easier
integration between different structures.

(c) Capability to be Synchronous or Asynchronous: Synchronicity refers to the client’s connection to


the function’s execution. The client is blocked and the client has to wait for the service to complete
its operation, before continuing in synchronous invocations. Asynchronous operations allow a client
to invoke a task and then continue with other tasks.
Asynchronous clients get their results later, but synchronous clients get their effect immediately
when the service is completed. The ability to enable loosely linked systems requires asynchronous
capabilities.

(d) Coarse-Grained: Object-oriented systems, such as Java, make their services available through
individual methods. At the corporate level, a character technique is far too fine an operation to be
useful. Building a Java application from the ground, necessitates the development of several fine-
grained strategies, which are then combined into a rough-grained provider that is consumed by
either a buyer or a service.
Corporations should be coarse-grained, as should the interfaces they expose. Web services
generation is an easy approach to define coarse-grained services that have access to enough
commercial enterprise logic.

(e) Supports Remote Procedural Call: Consumers can use an XML-based protocol to call procedures,
functions, and methods on remote objects utilizing web services. A web service must support the
input and output framework exposed by remote systems.
Enterprise-wide component development Over the last few years, JavaBeans (EJBs) and.NET
Components have become more prevalent in architectural and enterprise deployments. A number of
RPC techniques are used to allocate and access both technologies.
A web function can support RPC by offering its own services, similar to those of a traditional role, or
by translating incoming invocations into an EJB or.NET component invocation.

(f) Supports Document Exchanges: One of XML’s most appealing features is its simple approach to
communicating with data and complex entities. These records can be as simple as talking to a current
address or as complex as talking to an entire book or a Request for Quotation. Web administrations
facilitate the simple exchange of archives, which aids incorporate reconciliation.
The web benefit design can be seen in two ways: (i) The first step is to examine each web benefit on-
screen character in detail. (ii) The second is to take a look at the rapidly growing web benefit
convention stack.

Advantages Of Web Service

Using web services has the following advantages:

(a) Business Functions can be exposed over the Internet: A web service is a controlled code
component that delivers functionality to client applications or end-users. This capability can be
accessed over the HTTP protocol, which means it can be accessed from anywhere on the internet.
Because all apps are now accessible via the internet, Web services have become increasingly
valuable. Because all apps are now accessible via the internet, Web services have become
increasingly valuable. That is to say, the web service can be located anywhere on the internet and
provide the required functionality.

(b) Interoperability: Web administrations allow diverse apps to communicate with one another and
exchange information and services. Different apps can also make use of web services. A .NET
application, for example, can communicate with Java web administrations and vice versa. To make
the application stage and innovation self-contained, web administrations are used.

(c) Communication with Low Cost: Because web services employ the SOAP over HTTP protocol, you
can use your existing low-cost internet connection to implement them. Web services can be
developed using additional dependable transport protocols, such as FTP, in addition to SOAP over
HTTP.

(d) A Standard Protocol that Everyone Understands: Web services communicate via a defined
industry protocol. In the web services protocol stack, all four layers (Service Transport, XML
Messaging, Service Description, and Service Discovery) use well-defined protocols.

(e) Reusability: A single web service can be used simultaneously by several client applications.

2) Service Oriented Architecture


Service-Oriented Architecture (SOA) is an architectural pattern in
software design where services are provided to other applications
through a network, usually over the internet. SOA allows for the reuse of
existing services, which can be combined in various ways to create
applications. This architecture is characterized by its principles and
components that ensure services are well-defined, self-contained, and
interact through well-established protocols.
Core Components of SOA
Service Provider and Consumer
In SOA, there are two primary roles: the service provider and the service
consumer. The service provider creates and maintains the service,
making it available for others to use. They publish the service in a
registry with a contract that specifies how to use it, the requirements,
and any associated fees1. The service consumer, on the other hand,
locates the service in the registry and develops the necessary
components to bind and use the service1.
Guiding Principles
SOA is governed by several guiding principles that dictate how services
should be created and managed:
 Standardized service contract: Services are defined by one or more
service description documents.
 Loose coupling: Services maintain relationships that minimize
dependencies and are designed as self-contained components.
 Abstraction: Services hide their logic from the consumer, fully defined by
their contracts.
 Reusability: Services are designed to be reusable components, reducing
development time and costs.
 Autonomy: Services have control over their encapsulated logic.
 Discoverability: Services can be discovered effectively through their
description documents.
 Composability: Services can be used as building blocks for more complex
operations12.
SOA Layers
SOA includes various layers that interact with each other:
 Consumer Interface Layer: Interacts with the user and provides the user
interface.
 Business Process Layer: Contains all business applications.
 Services Layer: Where all services are run.
 Service Component Layer: Stores functional and technical applications.
 Operational Systems Layer: Contains the data model of the system3.
Service Repository and Service Bus
The service repository is where services are stored and managed. It acts
as a central point where services can be accessed and orchestrated. The
service bus facilitates communication between services, ensuring that
data is passed correctly from one service to another3.
Business Activity Monitoring (BAM)
BAM is used to monitor the performance of processes within SOA. It
provides visibility into the system, allowing for the creation of reports
and dashboards to track the state and speed of processes3.
Operational Data Store (ODS)
ODS provides synchronized data from a customer perspective, offering
insights into business operations and facilitating data transfer between
services3.
Security
Security in SOA is critical due to the sensitive data involved. Security
measures are implemented across all components to ensure data
integrity and prevent unauthorized access3.
Management
Management in SOA involves overseeing the loosely coupled
components to ensure optimal performance. Operators monitor system
status and performance, addressing any potential threats3.
Advantages and Disadvantages of SOA
Advantages:
 Service reusability: Services can be reused across multiple applications.
 Easy maintenance: Independent services can be updated without
affecting others.
 Platform independence: SOA supports the integration of services from
various sources.
 Reliability: Smaller services are easier to debug and test.
 Scalability: Services can run on different servers, enhancing scalability1.
Disadvantages:
 High overhead: Validation of input parameters can decrease
performance.
 High initial investment: Implementing SOA requires significant upfront
costs.
 Complex service management: Managing a large number of messages
can be challenging1

3) Types of Web Services


Web Services – Definition, Working, Types,
Applications
Web Service is the set of rules or guidelines which enable
communication among different applications via the World wide web
(.i.e. the internet). Before web service, there were other technologies
but some of them have dependencies such as EJB (enterprise java bean)
which allows applications to communicate only if the applications are
working on Java, these dependencies make communication difficult.
These dependencies are removed by web services.
In the present world, applications are developed on a variety of
programming languages such as Java, Python, PHP, etc. These
heterogeneous applications need communication to happen between
them. Since they are developed in different programming languages it
becomes difficult to ensure efficient communication between them.
Here is where web services come into the picture, web services provide
a language-independent way of communication that means the
applications working on Java can communicate with other applications
working on Python. Therefore, web service helps us to invoke the
functionality of other programs in the existing program.

Why application needs to communicate


While working, some applications might need to use the service or
functionality offered by other applications. To use that service or
functionality applications need to communicate with each other. Let us
consider an example of a restaurant, when you visit the restaurant and
ask for the food(a service) then the waiter will be taking the order to the
kitchen and serve you prepared food from the kitchen. Here the waiter is
like the web service which allows you(.i.e. client) to communicate with
the kitchen(.i.e. application).
The figure below shows another example of how the ICICI bank ATM
used the service provided by SBI bank to access the database of the
customer which cannot be accessed by the ICICI bank ATM directly.

How do web services work?


Web services use the request-response method to communicate among
applications. For any communication, we need a medium and a common
format that can be understood by everyone, in the case of web services
medium is the internet and the common format is the XML (Extensible
Markup Language) format as every programming language can
understand the XML markup language.
A client is the one that requests some service from the server that is
known as the service provider. The request is sent through a message
which is in common XML format and in response to that request, the
service provider will respond with a message in a common format (.i.e.
XML).

Web Service Components


1. SOAP: As mentioned above SOAP stands for Simple Object Access
Protocol. It is the protocol stating how the communication between the
application is going to happen.
2. WSDL: It stands for Web Services Description Language which is the
XML document containing the rules for communication among different
software. It defines that:
 How that service can be accessed by the system requesting for it from
other systems
 What is the name of the service
 What are the specific parameter needed for accessing that service, what
would be the return type
 What are the error messages that would be displayed in case of any
issue while accessing the data.
3. UDDI: Universal Description, Discovery, and Integration is the full form
for the UDDI. It is a directory that provides us the detail that which
software needs to be contacted for the particular type of data.

Types of web services


There are mainly two types of web services:
1. SOAP web services: SOAP stands for Simple Object Access Protocol.
These protocols are based on XML which is a lightweight data exchange
language. These protocols are independent of language and can be run
on any platform.
SOAP supports both stateful and stateless operations. Stateful means
that the server keeps track of the information received from the client on
each request. While Stateless means that each request contains enough
information about the state of the client and thus server does not need
to bother about saving the state of the client thus increasing the speed
of communication.
Many companies such as IBM, Microsoft are producing an
implementation of SOAP into their systems.
2. RESTful web services: It stands for Representational State Transfer.
They are also language and platform-independent and are faster in
comparison to SOAP. Nowadays RESTful web services are more used than
SOAP. They treat the data as resources. RESTful web services return data
in JSON format or XML format. These web services create the object and
send the state of the object in response to the client’s requests, that’s
why known as Representational State Transfer.
Characteristics of web services
Following are the characteristics of web services:
1. Web services are XML-based as they use XML as a standard language for
data exchange as XML allows flexible coding and decoding of data with
every programming language and operating system.
2. Web services are coarse-grained. It means they have broader
functionality and scope of operations. It is cheaper and provides more
fine-grained services in one coarse-grained service.
3. Web Services supports RPCs (Remote Procedure Calls). Web services that
use the RPCs style are synchronous, which means the client has to wait
for the response after the request. RPCs allows a program to invoke
procedure and functions on remote objects.
4. Web services allow loose coupling with the systems that means systems
are weekly associated with each other. Web service does not concern
with the state of the system involved in the process of communication.
5. Web Services are Synchronous and Asynchronous. In synchronous web
services, the client will wait for the response until the server sends the
response. Synchronous web service is provided through RPC
communication. In Asynchronous web services, the client will not wait
for the response and in the meantime, it can continue with other
operations processing.

4) SOAP based Web Services


Basics of SOAP – Simple Object Access Protocol
imple Object Access Protocol(SOAP) is a network protocol for
exchanging structured data between nodes. It uses XML format to
transfer messages. It works on top of application layer protocols
like HTTP and SMTP for notations and transmission. SOAP allows
processes to communicate throughout platforms, languages, and
operating system, since protocols like HTTP are already installed on all
platforms. SOAP was designed by Bob Atkinson, Don Box, Dave Winer,
and Mohsen Al-Ghosein at Microsoft in 1998. SOAP was maintained by
the XML Protocol Working Group of the World Wide Web Consortium
until 2009.

Message Format
SOAP message transmits some basic information as given below
 Information about message structure and instructions on processing it.
 Encoding instructions for application-defined data types.
 Information about Remote Procedure Calls and their responses.
The message in XML format contains four parts-
 Envelope: This specifies that the XML message is a SOAP message. A
SOAP message is an XML document containing a header and a body,
both encapsulated within the envelope. Any fault is included within the
body of the message.
 Header: This part is optional. When present, it can provide crucial
information about the applications.
 Body: This contains the actual message being transmitted. Faults are
contained within the body tags.
 Fault: This optional section contains the status of the application and
any errors. It should not appear more than once in a SOAP message.
Sample Message
xml
Content-Type: application/soap+xml
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-
envelope">
<env:Header>
<m:GetLastTradePrice xmlns:m="Some-URI" />
</env:Header>
<env:Body>
<symbol xmlns:p="Some-URI" >DIS</symbol>
</env:Body>
</env:Envelope>
Advantages of SOAP
 SOAP is a light weight data interchange protocol because it is based on
XML.
 SOAP was designed to be OS and Platform independent.
 It is built on top of HTTP which is installed in most systems.
 It is suggested by W3 consortium which is like a governing body for the
Web.
 SOAP is mainly used for Web Services and Application Programming
Interfaces (APIs).

5) RESTful Web Services


RESTful Web Services
REST or Representational State Transfer is an architectural style that
can be applied to web services to create and enhance properties like
performance, scalability, and modifiability. RESTful web services are
generally highly scalable, light, and maintainable and are used to create
APIs for web-based applications. It exposes API from an application in a
secure and stateless manner to the client. The protocol for REST is
HTTP. In this architecture style, clients and servers use a standardized
interface and protocol to exchange representation of resources.
REST emerged as the predominant Web service design model just a
couple of years after its launch, measured by the number of Web
services that use it. Owing to its more straightforward style, it has
mostly displaced SOAP and WSDL-based interface design.
REST became popular due to the following reasons:
1. It allows web applications built using different programming languages
to communicate with each other. Also, web applications may reside in
different environments, like on Windows, or for example, Linux.
2. Mobile devices have become more popular than desktops. Using REST,
you don’t need to worry about the underlying layer for the device.
Therefore, it saves the amount of effort it would take to code
applications on mobiles to talk with normal web applications.
3. Modern applications have to be made compatible with the Cloud. As
Cloud-based architectures work using the REST principle, it makes
sense for web services to be programmed using the REST service-based
architecture.
RESTful Architecture:
1. Division of State and Functionality: State and functionality are divided
into distributed resources. This is because every resource has to be
accessible via normal HTTP commands. That means a user should be
able to issue the GET request to get a file, issue the POST or
PUT request to put a file on the server, or issue the DELETE request to
delete a file from the server.
2. Stateless, Layered, Caching-Support, Client/Server Architecture: A type
of architecture where the web browser acts as the client, and the web
server acts as the server hosting the application, is called a
client/server architecture. The state of the application should not be
maintained by REST. The architecture should also be layered, meaning
that there can be intermediate servers between the client and the end
server. It should also be able to implement a well-managed caching
mechanism.
Principles of RESTful applications:
1. URI Resource Identification: A RESTful web service should have a set of
resources that can be used to select targets of interactions with clients.
These resources can be identified by URI (Uniform Resource
Identifiers). The URIs provide a global addressing space and help with
service discovery.
2. Uniform Interface: Resources should have a uniform or fixed set of
operations, such as PUT, GET, POST, and DELETE operations. This is a
key principle that differentiates between a REST web service and a non-
REST web service.
3. Self-Descriptive Messages: As resources are decoupled from their
representation, content can be accessed through a large number of
formats like HTML, PDF, JPEG, XML, plain text, JSON, etc. The metadata
of the resource can be used for various purposes like control caching,
detecting transmission errors, finding the appropriate representation
format, and performing authentication or access control.
4. Use of Hyperlinks for State Interactions: In REST, interactions with a
resource are stateless, that is, request messages are self-contained. So
explicit state transfer concept is used to provide stateful interactions.
URI rewriting, cookies, and form fields can be used to implement the
exchange of state. A state can also be embedded in response messages
and can be used to point to valid future states of interaction.
Advantages of RESTful web services:
1. Speed: As there is no strict specification, RESTful web services are
faster as compared to SOAP. It also consumes fewer resources and
bandwidth.
2. Compatible with SOAP: RESTful web services are compatible with
SOAP, which can be used as the implementation.
3. Language and Platform Independency: RESTful web services can be
written in any programming language and can be used on any platform.
4. Supports Various Data Formats: It permits the use of several data
formats like HTML, XML, Plain Text, JSON, etc.
Example :
Here is an example of a simple RESTful service that allows a client to
create, read, update, and delete (CRUD) a resource :
Javascript
// GET /resource/123
// Returns the state of the resource with ID 123
app.get('/resource/:id', function(req, res) {
var id = req.params.id;
var resource = findResourceById(id);
res.json(resource);
});

// POST /resource
// Creates a new resource with the state specified in the request body
app.post('/resource', function(req, res) {
var resource = req.body;
var id = createResource(resource);
res.json({ id: id });
});

// PUT /resource/123
// Updates the state of the resource with ID 123 with the state specified in the requ
app.put('/resource/:id', function(req, res) {
var id = req.params.id;
var resource = req.body;
updateResource(id, resource);
res.sendStatus(200);
});

// DELETE /resource/123
// Deletes the resource with ID 123
app.delete('/resource/:id', function(req, res) {
var id = req.params.id;
deleteResource(id);
res.sendStatus(200);
});

In this example, the service uses the GET, POST, PUT, and DELETE HTTP
methods to implement the CRUD operations on a resource. The service
uses the app.get(), app.post(), app.put(), and app.delete() methods to
register the appropriate handler functions for each operation. The req
and res objects represent the request and response, respectively, and
are used to access information about the request and send a response
to the client.

6) How to create RESTful Services


RESTful web services are an architectural style for building scalable and
maintainable web services. They are based on
the REST (Representational State Transfer) architecture, which uses
standard HTTP methods to perform operations on resources
represented by URLs. RESTful services are stateless, meaning each
request from a client to the server must contain all the information
needed to understand and complete the request.
Key Principles of RESTful Services
RESTful web services are designed around resources, which are any
kind of objects, data, or services that can be accessed by the client. A
resource has a URI (Uniform Resource Identifier) to uniquely identify it.
The interaction with these resources is performed using the standard
HTTP methods:

 GET: Retrieve a resource.


 POST: Create a new resource.
 PUT: Update an existing resource.
 DELETE: Delete a resource.

These methods correspond to create, read, update, and delete (CRUD)


operations, respectively.
RESTful Services in Action
Here's a simple example of how RESTful services work:
// GET /resource/123
// Returns the state of the resource with ID 123
app.get('/resource/:id', function(req, res) {
var id = req.params.id;
var resource = findResourceById(id);
res.json(resource);
});
// POST /resource
// Creates a new resource with the state specified in the request body
app.post('/resource', function(req, res) {
var resource = req.body;
var id = createResource(resource);
res.json({ id: id });
});

// PUT /resource/123
// Updates the state of the resource with ID 123 with the state
specified in the request body
app.put('/resource/:id', function(req, res) {
var id = req.params.id;
var resource = req.body;
updateResource(id, resource);
res.sendStatus(200);
});

// DELETE /resource/123
// Deletes the resource with ID 123
app.delete('/resource/:id', function(req, res) {
var id = req.params.id;
deleteResource(id);
res.sendStatus(200);
});

In this code snippet, a RESTful service is defined using JavaScript,


where each HTTP method is associated with a specific route and a
function that handles the request and sends a response.
Benefits of RESTful APIs
 Scalability: Due to their stateless nature and ability to cache responses,
RESTful services can handle a large number of requests and scale
effectively.
 Flexibility and Independence: Clients and servers can evolve
independently, as long as the interface between them remains
unchanged. RESTful services can be consumed by various clients,
including browsers and mobile devices.
 Language and Platform Agnosticism: RESTful services can be written in
any programming language and run on any platform, facilitating
integration between systems.
RESTful Services and the Cloud
With the advent of cloud computing, RESTful services have become
even more relevant. Cloud platforms often expose their functionalities
through RESTful APIs, allowing developers to integrate with them
seamlessly.

You might also like