Web Service Introduction

In this article, We will see what is web Service? How is web Service useful? Why you need webServices ? What are the Types of WebService? and much more.
 

What is Web Service ?

A service-oriented architecture is essentially a collection of services. Web service is a way of communication, Web Service allows interoperability between different applications on different platforms. For example, a java based application on Windows can communicate with a .Net based one on Linux. The communication can be done through a set of XML messages over HTTP protocol or SOAP Protocol.

Web services are browsers and operating system independent, which means it can run on any browser without the need of making any changes.

 

What is need of Web Services?

Web Services is very useful software services. Let’s see the pointed and descriptive explanation of web services.
 
1. Code Reusability:  Suppose you are developing a Healthcare software on java and you have an old .net software which manages patients insurance. So rather than develop a new software for insurance part,you can use old software and for other  business requirements, you can develop your code in java. Using this way you can reuse the old application code and communicate with the old application using WebServices.

 

2. Interoperability It’s the most important benefit of Web Services. Web Services typically work outside of private networks, offering developers a non-proprietary route to their solutions.

Web Services also let developers use their preferred programming languages. In addition, thanks to the use of standards-based communications methods, Web Services are virtually platform-independent.

 

3. Loosely Coupled: Webservices are independent of each other. Each service exists independently of the other services that make up the application. Individual pieces of the application to be modified without impacting unrelated areas.
 

 5. Deployability: Web Services are deployed over standard Internet technologies. This makes it possible to deploy Web Services even over the firewall to servers running on the Internet on the other side of the globe. Also thanks to the use of proven community standards, underlying security (such as SSL) is already built-in.

 

WebServices Specifications

Three specifications for Web Services are illustrated in this section: SOAP, REST, and JSON.

 

1.  SOAP : SOAP stands for Simple Object Access Protocol. SOAP is a protocol specification for exchanging structured information in the implementation of Web services in computer networks. It relies on XML as its message format. SOAP was originally part of the specification that included the Web Services Description Language (WSDL) and Universal Description, Discovery, and Integration (UDDI). It is used now without WSDL and UDDI. Instead of the discovery process described in the History of the Web Services Specification section below, SOAP messages are hard-coded or generated without the use of a repository.

 

2. REST : Representation State Transfer (REST) appeals to developers because it has a simpler style that makes it easier to use than SOAP. The use of REST is often preferred over the more heavyweight SOAP (Simple Object Access Protocol) style because REST does not leverage as much bandwidth, which makes it a better fit for use over the Internet. The SOAP approach requires writing or using a provided server program (to serve data) and a client program (to request data).

 

3. JSON : While both SOAP and REST use XML for interchange, JavaScript Object Notation (JSON) uses a subset of JavaScript. JSON Web Services let you access portal service methods by exposing them as a JSON HTTP API. Service methods are made easily accessible using HTTP requests, both from JavaScript within the portal and from any JSON-speaking client.

 

What is WSDL ?

WSDL stands for Web Service Description Language. It is an XML file that describes the technical details of how to implement a web service, more specifically the URI, port, method names, arguments, and data types. Since WSDL is XML, it is both human-readable and machine-consumable, which aids in the ability to call and bind to services dynamically.

 

Elements of WSDL :

Description:
It is the root element of a WSDL file. It usually contains a set of namespace declarations which are used throughout the WSDL file. 

Types:
The WSDL types element describes the data types used by your web service. Data types are usually specified by XML schema. It can be described in any language as long as your web services API supports it.

Binding:
The WSDL binding element describes how your web service is bound to a protocol. In other words, how your web service is accessible. To be accessible, the web service must be reachable using some network protocol. This is called “binding” the web service to the protocol.

Interface:
The WSDL interface element describes the operations supported by your web service. It is similar to methods in the programming language. The client can only call one operation per request.

Service:
It describes the endpoint of your web service. In other words, the address where the web service can be reached.

Endpoint:
The endpoint element describes the address of the web service. The endpoint binding attribute describes what binding element this endpoint uses.i.e. protocol with which you will access web service. The address attribute describes the URI at which you can access the service.

Message:
The message element describes the data being exchanged between the Web service providers and consumers.
 

Sample WSDL file:

<?xml version=”0.1″ encoding=”UTF-8″?>
<wsdl:definitions targetNamespace=”http://webservices.esaybix.com” xmlns:apachesoap=”http://xml.apache.org/xml-soap” xmlns:impl=”http://webservices.esaybix.com” xmlns:intf=”http://webservices.esaybix.com”
xmlns:wsdl=”http://schemas.xmlsoap.org/wsdl/” xmlns:wsdlsoap=”http://schemas.xmlsoap.org/wsdl/soap/” xmlns:xsd=”http://www.w3.org/2001/XMLSchema”>
<!–WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)–>
<wsdl:types>
<schema elementFormDefault=”qualified” targetNamespace=”http://webservices.esaybix.com”
xmlns=”http://www.w3.org/2001/XMLSchema”>
<element name=”HelloWorld”>
<complexType>
<sequence>
<element name=”name” type=”xsd:string”/>
</sequence>
</complexType>
</element>
<element name=”HelloWorldResponse”>
<complexType>
<sequence>
<element name=”HelloWorldReturn” type=”xsd:string”/>
</sequence>
</complexType>
</element>
</schema>
</wsdl:types>
<wsdl:message name=”HelloWorldRequest”>
<wsdl:part element=”impl:HelloWorld” name=”parameters”/>
</wsdl:message>
<wsdl:message name=”HelloWorldResponse”>
<wsdl:part element=”impl:HelloWorldResponse” name=”parameters”/>
</wsdl:message>
<wsdl:portType name=”HelloWorld”>
<wsdl:operation name=”HelloWorld”>
<wsdl:input message=”impl:HelloWorldRequest” name=”HelloWorldRequest”/>
<wsdl:output message=”impl:HelloWorldResponse” name=”HelloWorldResponse”/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name=”HelloWorldSoapBinding” type=”impl:HelloWorld”>
<wsdlsoap:binding style=”document” transport=”http://schemas.xmlsoap.org/soap/http”/>
<wsdl:operation name=”HelloWorld”>
<wsdlsoap:operation soapAction=””/>
<wsdl:input name=”HelloWorldRequest”>
<wsdlsoap:body use=”literal”/>
</wsdl:input>
<wsdl:output name=”HelloWorldResponse”>
<wsdlsoap:body use=”literal”/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name=”HelloWorldService”>
<wsdl:port binding=”impl:HelloWorldSoapBinding” name=”HelloWorld”>
<wsdlsoap:address location=”http://localhost:8080/SimpleSOAPExample/services/HelloWorld”/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

 

Web service design approaches:

Contract last or Bottom-up approach:
When using contract last approach,you first write your java code then you create web service contract(WSDL) .There are various kinds of tools which can generate WSDL on the basis of java code.

 

Contract first or Top Down Approach :
It  is a reverse of contract first.Here you first define web service contract.You define all the elements of WSDL first then after that you create your java logic.
4 Comments
  1. Sandeep 3:15 PM / October 13, 2016 - Reply

    Easy, Comprehensive, Informative ….. Wonderful article on web services

  2. Satya 8:26 PM / November 8, 2016 - Reply

    Hi Ashul..

    Please include a tutorial about web service automation testing using selenium.

    • Mark 9:29 AM / May 26, 2017 - Reply

      Hi Satya,

      We are planning to include the same. Wen Services Tutorials will be live within a month now.

  3. sravya 8:26 AM / June 3, 2017 - Reply

    Thanks for sharing this useful post.

Leave a Reply