Extending Web Service Capabilities
Extending Web Service Capabilities
A web service is an open standardized medium to generate communication between client and server
applications over network for exchanging information between two devices.
The customer act as the service customer, the Kitchen acts like a service provider and the waiter acts like
an API (Application Programming Interface). Here the customer order the food items from menu and the
waiter makes the note of it and send the request to the kitchen so the required item will be processed and
send back the response back to the customer. Thus, the food will be delivered to the customer. The waiter
as API will understand the language and act as the communication medium between two services.
WSDL
UDDI
WSDL (Web Services Description Language):
WSDL is an XML pattern for depicting system administrations and how to utilize them. It portrays tasks
and messages are theoretically.
WSDL components:
Definitions: Definitions are the central component of all WSDL reports. It is made reference to in
XML composition and includes both message definitions and information type definitions that
access the information type definitions
Operations: Operations is the applied definition for the messages help by a Web benefit.
Service binding: It depicts the substance in document and convention points of interest for a web
benefit.
Data Types: Messages are utilized as XML patterns in information types.
Message: It is an applied meaning of the information, the whole archive is exhibited as a message
and technique conjuring to be mapped.
Port type: characterizing the gathering of activities for an authoritative and it's a unique
arrangement of tasks mapped to at least one end-focuses and it tends to be mapped to different
transports through different ties.
Binding − It contains information organizations and convention for the arrangement of activities
and substance characterized for a specific port sort.
Port – port is a mix of system address and official, giving administration correspondence of the
objective location.
Working of SOAP:
The SOAP specification exposes a standard, XML-based way to encode requests and responses,
including:
Requests to invoke a method on a service, including in parameters
Responses from a service method, including return value and out parameters
Errors from a service
Envelope: Envelope is the root element and defines the start and the end of the message. It is a
mandatory element.
Header: Header is an optional sub element and contains attributes like credentials, API keys,
security information. This application related information is used in processing the message,
either at an intermediary point or at the ultimate end-point.
Body: This element is mandatory. It contains XML data comprising the message intended for the
receiver.
Fault: This element is optional and is the sub element of SOAP body. It is used for reporting
errors that occur while processing the message.
2. RESTful
REST stands for REpresentational State Transfer and was coined by Roy Fielding in 2000 as part of his
doctoral dissertation. REST is a software architecture style in contrast to a set of standards. It does not
impose any restriction on the format of a resource representation. Web services complying REST
architecture are called RESTful web services.
REST architecture describes Text Files, Html Pages, Images or any object that you may need to share to
other services as a resource. Each resource is identified by Uniform Resource Identifier (URI).
1. Client-Server
Client and server are separated from each other. User can make changes to the client and server
application independently without impacting each other. This improves scalability of the
application.
2. Stateless
REST API is stateless i.e. requests can be made independently of each other. Each request
contains all the necessary information such as access token, user ID, API key, etc to complete
itself successfully. REST APIs do not take advantage of data stored on the server to determine
what to do with a call. This reduces memory requirements and keep the application scalable
because sessions are stored on the client and not on the server.
3. Cache
Stateless APIs can increase request overhead by handling loads of incoming and outbound call.
Hence, REST encourages the storage of cacheable data. Response indicates that the data is
cacheable and can be stored up to a certain time or data needs to be real-time and response should
not be cached by the client (non-cacheable). This reduces the number of interactions with API
and internal server usage.
4. Uniform Interface
REST does not have application’s services, models, or actions tightly coupled to the API layer
but a uniform interface that allows independent evolution of the application. The uniform
interface simplifies the system architecture and lets the client interact with the server in a single
language, independent of the architectural backend of either.
5. Layered System
REST has a layered system where each layer has a specific functionality and responsibility. This
style allows an architecture of hierarchical layers that helps to create a more scalable and modular
application.
6. Code on Demand:
REST creates a smart application by allowing code to be transmitted via the API in the form of
applets and scripts. This reduces the number of features to be pre - implemented. The application
is no longer completely dependent on its own code structure.
SOAP only uses XML. REST permits different data formats like XML,
JSON,
SOAP defines its own security. RESTful web services inherits security measures
from the underlying transport.
SOAP web services use JAX-WS as the java API. RESTful web services use JAX-WS as the Java
API
DEMONSTRATION
JAX-WS is a standard XML based Java API to produce and consuming web services. In the following
section, a step by step approach for creating and utilizing Java based web services is demonstrated
SOAP Implementation:
Server application:
1. Create a new project and create a interface with methods that are going to be exposed as web
service
2. Add the logics that the webservice going to perform in the methods of the implementation class
a. The method getAllNotices return a list of notices
b. The method insertNotice takes a notice as input and add it to an existing list.
3. Set up SOAP based web services by creating web services for the implementation class
a. Web Services type – Bottom up approach is used to create the web services as it generates the
WSDL file (The web service contract) from the implementation logic. Another type of webservice,
Top down approach can be used when WSDL is given to generate the implementation logics.
b. Client generation (optional) - For testing the web service logic, a java proxy test client will be
generated depending upon the level of client selected.
4. WSDL file generation - In the next step, the methods to be included in the WSDL file should be
selected.
Client application:
This section deals with integrating our application with an SMS service provider which allows the user to
send text messages to mobile numbers via the internet. SMS API allows to send text messages in bulk,
triggers transactional alerts and OTP, receive inbound SMS, pull reports, and manage contacts. Several
third-party SMS service provider gateways are available and we have used Textlocal messaging service.
Host: https://api.txtlocal.com/send/
Content-Type: "application/x-www-form-urlencoded"
Parameters:
SUCCESS: FAILURE:
Steps to Integrate with Textlocal Messaging Service using JSP and Java Servlets:
1. Create JSP page (smsView.jsp) with a form element that fetches the details (Sender’s name, Mobile
number and Message) from the user and posts the data to a Servlet (SmsServlet.java).
2. Include the JSP Servlet mapping in the web.xml file using servlet-mapping.
3. The doPost method of the Servlet class (SmsServices.java) receives the request and generates an
HTTP POST request to be sent to the third party application. The sender’s name, mobile number,
message and API key are sent in the body of the request. The response received is then parsed and
forwarded to another JSP page (responseView.jsp).
4. Depending on the response received from the POST request, a success or failure message is
displayed using JSP (responseView.jsp).
Result:
1. Web Page:
2. SMS received:
REFERENCES:
http://www.springboottutorial.com/introduction-to-web-services-with-soap-and-rest
https://www.codementor.io/java/tutorial/soap-and-rest-java-web-services
https://www.udemy.com/web-services-api-step-by-step-beginner-tutorial/
https://youtu.be/s7wmiS2mSXY