Lecture Week 04: Web
Services
Adopted from Notes of Dr. Hamed Hamzeh
13/02/2025
Introduction
• "Think about how different websites (banks, shipping companies, payment processors) interact when you buy
something online. They 'talk' to each other behind the scenes to handle payment, shipping, and inventory. Web
services enable this seamless communication.“
• "How can different software systems, built with different technologies and
running on different platforms, communicate and exchange data effectively?“
• "How can we build applications that are modular, reusable, and can easily
integrate with other systems?“
• "How can we expose our application's functionality to other developers or
businesses in a standardised way?"
What Are Web Services?
Web Services are a standardised way of enabling
communication and data exchange between different
applications or systems over the internet.
Key Characteristics:
Interoperability: Facilitates Reusability: Encourages the Accessibility: Ensures easy
seamless communication development of modular and access to data and functionalities
between diverse systems. reusable code components. over the web.
What are web services?
An application can use the
capabilities of a Web
Web services represent a
service by simply invoking
new architectural
it across a network
paradigm for applications.
without having to integrate
it.
Example: Online Store Payments
You want to let customers pay on your online store with their credit cards.
Traditional Approach:
• Work with banks and understand complex financial regulations.
• Build secure systems to handle sensitive credit card information.
• Implement fraud detection and security measures
Web Service Solution:
• You use a payment gateway web service (like Stripe, PayPal, or Braintree).
• When a customer wants to pay, your store redirects them to the payment gateway's secure page.
• The customer enters their card details on the payment gateway.
• The payment gateway handles the whole transaction and notifies you back on success or failure.
Web Services advantages
01 02 03 04
Dramatically cut Reduce or Simplify Significantly
application eliminate many application reduce time-to-
development errors maintenance and market.
costs customization
Characteristics of Web
Services
Standardization
01 02 03
Serialisation Involves the Use of standard protocols Service Description: WSDL
use of established norms (e.g., SOAP, REST): leverage (Web Services Description
and protocols to ensure standardized communication Language). OpenAPI
consistency and protocols like SOAP (Simple (formerly Swagger)
interoperability. Object Access Protocol) and
REST (Representational State
Transfer) to enable seamless
data exchange between
applications.
How Does Serialization Work?
Serialization Mechanism: Format: The serialization mechanism
determines the format for the byte stream:
Your chosen programming language or library will provide a XML: Human-readable text format, good for cross-platform
serialization mechanism. This could be a built-in function, a data.
library, or a framework-specific serialization tool. JSON: More lightweight text format, ideal for web
interactions.
Binary formats: More compact, faster to process, but often
platform-specific.
Standardization
Imagine you're running a travel booking website and want to offer flight information from various
airlines.
Each airline might have its own API for providing flight data, with different formats and protocols.
Question: What would be the problem?
By using protocols like SOAP or REST, airlines can expose their data in a consistent way, making it
easier for your website to understand and interpret the information.
Additionally, standards for data formats like JSON or XML ensure the structure of the information
is consistent, removing the need for complex parsing and adaptation.
Interoperability
Interoperability refers to the ability of diverse systems to communicate and
work together.
Enabling communication between diverse systems: Web Services allow
different applications, often built on different technologies, to communicate
seamlessly.
Overcoming platform and language barriers: By using standard protocols
like SOAP or REST, Web Services facilitate communication between
applications developed on different platforms and in different programming
languages.
Example - interoperability
E-commerce Order Processing
Imagine an online store that wants to streamline its order fulfillment process.
The Problem: The store's systems are a combination of older software and more recent
additions:
• Its inventory management system runs on a Java platform.
• The shipping provider offers a .NET-based API for calculating rates and generating labels.
• The payment processing is handled by a third-party SaaS platform with a RESTful API.
The Goal: Make all these systems communicate seamlessly for automated order
processing, regardless of their underlying technologies.
Discoverability
Discoverability refers to the ability to find and locate web services efficiently.
Methods for discovering and locating services: Various methods, such as service
directories, registries, and standardized protocols, are employed to discover and
locate web services within a network.
Importance of service directories and registries: Centralized repositories, like
service directories and registries, play a crucial role in facilitating the discovery
process. They provide a structured way for services to be cataloged and accessed.
Let's consider a scenario where discoverability
plays a crucial role in web services
Imagine you're building a website that compares flights from various airlines
to find the best deals for users.
Here's how discoverability of relevant web services is essential:
Finding Airline Web Services
Solutions for Discoverability?
Solutions for discoverability
UDDI (Universal Description, Web Search and Industry
Discovery, and Integration): Repositories:
UDDI registries act like directories or yellow pages Airlines with web services might promote these on
for web services. their developer portals or within industry-specific
Airlines that want to make their flight search online repositories related to travel and booking.
functionality available to external partners can
register their services.
You could search these registries based on relevant
keywords.
Web service architecture
The simplest Web service system has two
participants:
A service producer A service consumer
(provider) (requester).
The provider presents the interface and
implementation of the service, and the
requester uses the Web service.
Web Service Architecture
– Service Oriented
A registry, acts as a broker for
Web services.
A provider, can publish
services to the registry
A consumer, can then discover
services in the registry
Web Service
Stack
Quality of Service (QoS)
Reliability: Ensuring that services Performance: Optimizing Scalability: The ability of the Security: Ensuring the
are available and function response times, throughput, and system to handle increased load confidentiality, integrity, and
correctly, with minimal downtime resource utilization to deliver by adding resources or nodes. authenticity of data and
and errors. services efficiently. communication.
Best practices for reliability!
Availability: Fault tolerance: Data integrity:
• It should have minimal • recover from failures and • It should handle data
downtime or disruptions continue operating without validation, ensure proper
significant impact on its data storage, and prevent
functionality or performance. data corruption or loss.
Monitoring and logging:
• track performance metrics,
log errors and exceptions Versioning and
Testing and validation
backward compatibility
Documentation and
support:significantly
impacting
Management
DISCOVERY: REGISTRATION: MONITORING: DEPLOYMENT: SCALING: HANDLING
MECHANISMS FOR SERVICES NEED TO BE CONTINUOUS TRACKING MANAGING THE THE SCALING OF
SERVICES TO DISCOVER REGISTERED AND OF SERVICE DEPLOYMENT OF SERVICES BASED ON
EACH OTHER AND THEIR MAINTAIN UP-TO-DATE PERFORMANCE, SERVICES IN VARIOUS DEMAND.
CAPABILITIES. INFORMATION. AVAILABILITY, AND ENVIRONMENTS.
USAGE METRICS.
VERSIONING:
MANAGING DIFFERENT
VERSIONS OF SERVICES
AND ENSURING
COMPATIBILITY.
Web Standards (W3C)
Is an international community that develops standards and
guidelines to ensure the long-term growth and accessibility of
the World Wide Web
Responsible for developing and maintaining a wide range of
technical specifications and guidelines that define the
technologies used on the web.
Bringing together various stakeholders including industry
leaders, researchers, developers, and public interest groups.
SOAP
SOAP (Simple Object Access Protocol) is a protocol for exchanging
structured information in web services.
It is a messaging protocol that allows programs running on different
operating systems to communicate with one another.
It is often employed in enterprise-level applications and scenarios
where a strict and standardized communication protocol is required.
Protocol Specifications
Standards and Specifications
• SOAP is governed by industry standards and specifications.
• W3C (World Wide Web Consortium) defines the SOAP standard.
Versions
• SOAP 1.1 and SOAP 1.2 are the widely used versions.
HTTP and Other Transport Protocols
• SOAP messages can be transported over various protocols, including HTTP.
XML-Based Format for Message Structure
• XML (eXtensible Markup Language)
• Platform-independent and human-readable.
• Used to define the structure of SOAP messages.
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:m="http://www.example.org">
<soap:Header>
<!-- Header content here -->
</soap:Header>
<soap:Body>
<!-- Body content here -->
</soap:Body>
</soap:Envelope>
SOAP
XML-based:
• SOAP messages are structured XML documents. This makes them platform-independent and human-
readable (though slightly verbose).
Envelope Structure: SOAP messages have a specific structure. They always include
an 'Envelope' element which contains a 'Header' (optional) and a 'Body’.
Header: Can carry extra information like security metadata, routing, or transaction
details.
Body: Contains the actual message payload (e.g., information about a function call
and its parameters).
WSDL
Purpose: An XML-based
language that describes the
capabilities of a web
Stands for: Web Services
service. Think of it as a
Description Language
'contract' defining how a client
application should interact
with the web service.
WSDL
Data Types: Describes the format of the
input and output messages the web
Operations: Lists the specific functions
service expects and produces. This can
or actions the web service offers (e.g.,
be done using simple data types (string,
calculateInterestRate, searchProducts).
integer) or more complex structures
defined in XML Schema.
Binding: Specifies the communication
protocol or mechanism (usually SOAP,
Endpoint: Provides the network address
but sometimes REST-like bindings are
(URL) where the web service can be
used) and the message format (e.g., how
accessed.
data is encoded within a SOAP
message).
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.example.com/calculator"
targetNamespace="http://www.example.com/calculator">
<message name="SubtractRequest">
<part name="num1" type="xsd:int"/>
<part name="num2" type="xsd:int"/>
</message>
<binding name="CalculatorBinding" type="tns:CalculatorPortType">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="add">
<soap:operation soapAction="http://www.example.com/calculator/add"/>
</operation>
<operation name="subtract">
<soap:operation
soapAction="http://www.example.com/calculator/subtract"/>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="CalculatorService">
<port name="CalculatorPort" binding="tns:CalculatorBinding">
<soap:address location="http://www.example.com/calculator/service"/>
</port>
</service>
</definitions>
The implementation and design of a web service
client
Choose a programming Generate or create Set up the client
language and client code: configuration:
framework: • Available in API • Endpoints, authentication
• Python with Flask, Java with specification, WSDL or SDKs
JAX-WS, etc.
Invoking functions Error handling Update and maintain
RESTful Web Services
REST (Representational State Transfer) is an architectural style for
designing networked applications.
RESTful Web Services use the principles of REST, emphasizing simplicity,
scalability, and statelessness.
REST is based on principles such as stateless communication, resource
identification, and uniform interfaces, contributing to its popularity for web
service development.
Introduction to RESTful Services
Representational State Transfer (REST) is an
architectural style for designing networked
applications.
It’s not a protocol or a standard, but a set of guiding
principles and constraints.
In REST, statelessness refers to
when the client is responsible for
storing and handling the session-
Principles of related information on its own side.
REST - Stateless
Communication Each request from the client to the
server must contain all the
information needed to process that
request.
Principles of REST - Client-Server
Architecture
In a RESTful architecture, the server and the client are clearly isolated
from each other.
While the server doesn’t know the user interface, the client doesn’t know
the application’s business logic or how the application persists data.
Principles of REST - Uniform Interface
REST defines a consistent and uniform interface for interactions between
clients and servers.
For example, the HTTP-based REST APIs make use of the standard HTTP
methods (GET, POST, PUT, DELETE, etc.) and the URIs (Uniform Resource
Identifiers) to identify resources.
Principles of REST - Uniform Interface
The core architectural
elements of a RESTful
system - URI
• A URI is a string of characters
used to identify a resource
over the Web.
• The client uses a URI to locate
the resources over Web and
then, sends a request to the
server and reads the
response.
Using an external service's functionality in
your client web service
Obtain API credentials: Read the documentation: Make HTTP requests: Handle the responses:
Many services require API keys or how to make requests, what appropriate HTTP methods (GET, responses may be in various
access tokens endpoints are available, and what POST, PUT, DELETE) to send formats such as JSON, XML, or
data formats are expected. requests to the endpoints others
JSON
Lightweight data interchange format.
Enclosed in curly braces {}.
Consists of key-value pairs.
JSON data syntax
• Arrays are enclosed in square
brackets ([ ]), and their values
are separated by a comma (,).
• Each value in an array may be
of a different type, including
another array or an object.
The HTTP GET method
The HTTP POST method The POST method is used
to create resources.
The HTTP PUT method The PUT method is used to
update resources.
The HTTP DELETE method
The Travel Agency App
What is a monolith: It's like a giant castle where all the parts of your app
(booking flights, reserving hotels, managing user accounts) live together
inside the same walls.
Pros: Can be simpler to start with.
Cons: As your app grows, it can be hard to change or scale one part without
affecting everything else.
Designing the Web Service
What does our travel app need to do? Let's list the features:
Search for flights (destination, dates, etc.)
View flight options and prices
Book flights
Search for hotels
Book hotels
Manage user accounts (login, profiles, trip history)
What kind of information the app needs
from outside to work?
Flights: Needs User
Hotels: Needs
data from airline accounts: Our app
data from hotel
systems will likely store this
booking services
(schedules, prices) data itself
Web service endpoints
Each feature will have its own 'endpoint'. An endpoint is like a special web address your
app uses to make a request:
/search-flights
/book-flight
/search-hotels
and so on...