Web Services Tutorial for Beginners

Web Services Tutorial.

In this web services tutorial for beginners, we will cover many important web services questions. First, an introduction to web services. What is web service? A web service is a software service provided by one device to another device via the web that is by using HTTP. The use of web services is to provide useful information like weather, stock market information, foreign exchange rates and so on. The web service runs as a software application on the web service provider. The technologies in which the service provider and client are written may be different. It does not matter because the communication between the service provider and client uses standard data formats like XML or JSON. Also, web services do not have a user interface. For example, a web server running on Linux may provide a web service to a web server running on Windows, which then uses the received data in its user interface to end-users. For this to happen, the client sends a request to the server and the server sends a response back to the client. Next in web services basics, let us see the advantages of web services.

Why web services?

The first reason is web services are built with service-oriented architecture. The client only needs a web service URL.

The client can send requests only when needed. The second advantage of web services is the server and the client may be located in any different geographical locations. The third advantage of web services is the server and the client may be written in different technologies like Java, PHP, C# etc. or running on different operating systems like Unix, Linux, Windows etc. The fourth advantage of using web services is that web services are written to be consumed by other software applications. The client only gets the requested data in the response. It is easier for the client to use a web service than having to “scrape” data from a web page, because a web page contains presentation elements also.

How web services work?

First, we need to understand XML, JSON, SOAP and WSDL because web service uses these standards. XML means Extensible Markup Language) and JSON means JavaScript Object Notation. XML or JSON describes the data. You can see my XML tutorials and JSON tutorial to learn more. SOAP means Simple Object Access Protocol). It is a protocol (that is, a set of rules) to send and receive messages between two applications. SOAP is used by the client to send the request and also, SOAP is used by the server to send the response. WSDL or “wizdal” means Web Services Description Language. What is WSDL in web services? WSDL web service defines the message specification, methods’ specifications and the location of the web service. The WSDL uses XML to describe the web service by showing web service methods and how to call them. We will soon see the sample web services.

How does a web service work?

Step 1) is the web service client needs to find the URL of the web service method. This URL is available in the web service’s WSDL.

Step 2) is the web service call. The web service client sends a request in JSON or XML to the server web service endpoint with arguments e.g. city and state to get the weather forecast.

Step 3), the server reads the request.

Step 4), the server prepares the response data e.g. for weather web service call, for weather web service, it prepares the response data with the minimum and maximum temperature, rainfall, wind speed and so on.

Step 5), the server sends a response to the client to consume web service.

Now, let us see some free web services. I have put the link to this list of web services. There are a number of web services available like Google Maps, Twitter and YouTube. And you can search for web services. Now, this is the LinkedIn API. It shows the API endpoint, API home page and so on. Here is another example of a web service. It is the weather web service. It shows the information on the current weather data, 5-day forecast and 16-day forecast. For example, here it shows the response data which has the weather in London, UK in the JSON data format. Now, let us see the types of web services. The first type is SOAP web services. SOAP or Simple Object Access Protocol web services use XML for communication between the client and the server. SOAP web service security uses WS Security. You can create SOAP web service using different web service technologies. Since SOAP web services use XML data format, they are slow. Also, only WSDL is available to discover SOAP web services. The second and newer type is RESTful web services. REST stands for Representational State Transfer. RESTful web services are completely stateless. They can use plain text, HTML, XML or JSON data formats for communication between the client and the server. REST web service security is inherited from the transport protocol that they use. Just like SOAP web services, RESTful web services can also be written using different web service technologies. RESTful web services are faster than SOAP web services because they don’t need to follow the many standards that the SOAP web services do. This means that they are better suited for mobile devices with limited bandwidth. RESTful web services are more popular than SOAP web services.