In the context of web services, operations refer to the specific functions or actions that a web service can perform when it is invoked by a client. These operations define the interaction between the client and the server, specifying what functionality is offered and how data is processed.
Web services, whether SOAP-based or RESTful, expose a set of operations to allow clients to request data or perform actions. These operations are defined in service descriptions and are crucial for the client-server communication.
In SOAP (Simple Object Access Protocol) web services, operations are defined in the WSDL (Web Services Description Language) document. WSDL serves as the contract between the client and the service, detailing the available operations, their input and output parameters, and the protocols that are supported.
SOAP Operations typically follow a request-response pattern, where the client sends a request message, and the service responds with a message. Each operation in a SOAP web service corresponds to a specific action that the service can perform.
In a WSDL file, an operation is defined within the <operation> tag inside the <portType> element. Each operation specifies its request and response messages, which are defined in the <message> element.
Example of a WSDL operation:
<definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" targetNamespace="http://example.com/service">
<portType name="BookService">
<operation name="GetBookDetails">
<input message="tns:GetBookDetailsRequest"/>
<output message="tns:GetBookDetailsResponse"/>
</operation>
</portType>
<binding name="BookServiceSoap" type="tns:BookService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="GetBookDetails">
<soap:operation soapAction="http://example.com/GetBookDetails"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
</definitions>
GetBookDetails and describes a specific action the service can perform (retrieving details about a book).GetBookDetails, the request and response are defined in the messages GetBookDetailsRequest and GetBookDetailsResponse.When a client invokes a SOAP operation like GetBookDetails, it might send a request message in XML format, such as:
Request (SOAP Envelope)
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://example.com/service">
<soapenv:Header/>
<soapenv:Body>
<web:GetBookDetails>
<web:BookID>12345</web:BookID>
</web:GetBookDetails>
</soapenv:Body>
</soapenv:Envelope>
The server processes the request and sends back a response:
Response (SOAP Envelope)
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://example.com/service">
<soapenv:Header/>
<soapenv:Body>
<web:GetBookDetailsResponse>
<web:BookTitle>Introduction to Web Services</web:BookTitle>
<web:Author>John Doe</web:Author>
<web:Year>2023</web:Year>
</web:GetBookDetailsResponse>
</soapenv:Body>
</soapenv:Envelope>
In REST (Representational State Transfer) web services, operations are mapped to HTTP methods (GET, POST, PUT, DELETE, etc.). Each HTTP method corresponds to a specific CRUD (Create, Read, Update, Delete) operation on the resources exposed by the service.
REST is stateless, and each operation is performed by sending an HTTP request to a specific URL (or endpoint) that represents a resource. The response can be in various formats, such as XML, JSON, or plain text.
Let's assume you have a RESTful web service for managing books, where each book is identified by a unique ID.
GET: Retrieve details of a book
/books/{id}GET /books/12345{
"bookID": "12345",
"title": "Introduction to Web Services",
"author": "John Doe",
"year": 2023
}
POST: Create a new book
/books{
"title": "Mastering REST",
"author": "Jane Smith",
"year": 2024
}
{
"bookID": "67890",
"title": "Mastering REST",
"author": "Jane Smith",
"year": 2024
}
PUT: Update an existing book
/books/12345{
"title": "Introduction to Web Services (Updated)",
"author": "John Doe",
"year": 2024
}
{
"bookID": "12345",
"title": "Introduction to Web Services (Updated)",
"author": "John Doe",
"year": 2024
}
DELETE: Delete a book
/books/12345DELETE /books/12345GraphQL is an alternative approach to traditional REST or SOAP web services. Instead of having predefined endpoints for specific actions (like GET or POST requests), GraphQL exposes a single endpoint that can handle a variety of operations through queries, mutations, and subscriptions.
query {
book(id: 12345) {
title
author
year
}
}
mutation {
createBook(title: "New Book", author: "Jane Doe", year: 2024) {
id
title
author
}
}
subscription {
newBook {
id
title
}
}
Web service operations are the core functions that enable clients to interact with web services. They define the actions that can be performed on the server-side, whether retrieving data, modifying resources, or performing specific business logic. The operation details, including input parameters, output formats, and communication protocols (SOAP, REST, or GraphQL), are key to defining how the client and server communicate in web service-based architectures. Understanding web service operations is essential for designing and consuming effective APIs, ensuring seamless data exchange and application integration.
Open this section to load past papers