Type of Web Service

There are mainly two types of web services.

  1. SOAP web services.
  2. RESTful web services.

In order for a web service to be fully functional, there are certain components that need to be in place. These components need to be present irrespective of whatever development language is used for programming the web service.

SOAP (Simple Object Access Protocol)

SOAP is known as a transport-independent messaging protocol. SOAP is based on transferring XML data as SOAP Messages. Each message has something which is known as an XML document. Only the structure of the XML document follows a specific pattern, but not the content. The best part of Web services and SOAP is that its all sent via HTTP, which is the standard web protocol.

Here is what a SOAP message consists of

  • Each SOAP document needs to have a root element known as the <Envelope> element. The root element is the first element in an XML document.
  • The “envelope” is in turn divided into 2 parts. The first is the header, and the next is the body.
  • The header contains the routing data which is basically the information which tells the XML document to which client it needs to be sent to.
  • The body will contain the actual message.

The diagram below shows a simple example of the communication via SOAP.

WSDL (Web services description language)

A web service cannot be used if it cannot be found. The client invoking the web service should know where the web service actually resides.

Secondly, the client application needs to know what the web service actually does, so that it can invoke the right web service. This is done with the help of the WSDL, known as the Web services description language. The WSDL file is again an XML-based file which basically tells the client application what the web service does. By using the WSDL document, the client application would be able to understand where the web service is located and how it can be utilized.

Web Service Example

An example of a WSDL file is given below.

<definitions>          

  <message name=”TutorialRequest”>

     <part name=”TutorialID” type=”xsd:string”/>

  </message>

  <message name=”TutorialResponse”>

     <part name=”TutorialName” type=”xsd:string”/>

  </message>

  <portType name=”Tutorial_PortType”>

     <operation name=”Tutorial”>

        <input message=”tns:TutorialRequest”/>

        <output message=”tns:TutorialResponse”/>

     </operation>

  </portType>

  <binding name=”Tutorial_Binding” type=”tns:Tutorial_PortType”>

     <soap:binding style=”rpc”

        transport=”http://schemas.xmlsoap.org/soap/http”/>

     <operation name=”Tutorial”>

        <soap:operation soapAction=”Tutorial”/>

        <input>

           <soap:body

              encodingStyle=”http://schemas.xmlsoap.org/soap/encoding/”

              namespace=”urn:examples:Tutorialservice”

              use=”encoded”/>

        </input>

                   <output>

           <soap:body

              encodingStyle=”http://schemas.xmlsoap.org/soap/encoding/”

              namespace=”urn:examples:Tutorialservice”

              use=”encoded”/>

        </output>

     </operation>

  </binding>

</definitions>

The important aspects to note about the above WSDL declaration are as follows;

  1. <message> – The message parameter in the WSDL definition is used to define the different data elements for each operation performed by the web service. So in the example above, we have 2 messages which can be exchanged between the web service and the client application, one is the “TutorialRequest”, and the other is the “TutorialResponse” operation. The TutorialRequest contains an element called “TutorialID” which is of the type string. Similarly, the TutorialResponse operation contains an element called “TutorialName” which is also a type string.
  2. <portType> – This actually describes the operation which can be performed by the web service, which in our case is called Tutorial. This operation can take 2 messages; one is an input message, and the other is the output message.
  3. <binding> – This element contains the protocol which is used. So in our case, we are defining it to use http (http://schemas.xmlsoap.org/soap/http). We also specify other details for the body of the operation, like the namespace and whether the message should be encoded.

Universal Description, Discovery, and Integration (UDDI)

UDDI is a standard for describing, publishing, and discovering the web services that are provided by a particular service provider. It provides a specification which helps in hosting the information on web services.

Now we discussed in the previous topic about WSDL and how it contains information on what the Web service actually does. But how can a client application locate a WSDL file to understand the various operations offered by a web service? So UDDI is the answer to this and provides a repository on which WSDL files can be hosted. So the client application will have complete access to the UDDI, which acts as a database containing all the WSDL files.

Just as a telephone directory has the name, address and telephone number of a particular person, the same way the UDDI registry will have the relevant information for the web service. So that a client application knows, where it can be found.

Web Services Advantages

We already understand why web services came about in the first place, which was to provide a platform which could allow different applications to talk to each other.

But let’s look at some other advantages of why it is important to use web services.

1.      Exposing Business Functionality on the network – A web service is a unit of managed code that provides some sort of functionality to client applications or end users. This functionality can be invoked over the HTTP protocol which means that it can also be invoked over the internet. Nowadays all applications are on the internet which makes the purpose of Web services more useful. That means the web service can be anywhere on the internet and provide the necessary functionality as required.

2.      Interoperability amongst applications – Web services allow various applications to talk to each other and share data and services among themselves. All types of applications can talk to each other. So instead of writing specific code which can only be understood by specific applications, you can now write generic code that can be understood by all applications

3.      A Standardized Protocol which everybody understands – Web services use standardized industry protocol for the communication. All the four layers (Service Transport, XML Messaging, Service Description, and Service Discovery layers) uses well-defined protocols in the web services protocol stack.

4.      Reduction in cost of communication – Web services use SOAP over HTTP protocol, so you can use your existing low-cost internet for implementing web services.

Related Posts

© 2024 Basic Computer Science - Theme by WPEnjoy · Powered by WordPress