What is a Web Service?

Asked

Viewed 10,103 times

45

Lately I’ve heard a lot about Web Service.

Web service is a solution used in systems integration and communication between different applications. Allow applications to send and receive data in XML format.

Web service is a solution used in systems integration and communication between different applications. With this technology it is possible that new applications can interact with those that already exist and that systems developed on different platforms are compatible. Web services are components that allow applications to send and receive data in XML format. Each application can have its own "language", which is translated into a universal language, the XML format.

Source: https://www.oficinadanet.com.br/artigo/447/o_que_e_web_service

I couldn’t visualize what a web service would be. But after all, what is it? Could anyone elucidate with any application that it can be used, maybe it will improve my understanding.

  • 9

    What’s the problem? So this question is not valid for the community just because there is a small explanation on the tag’s wiki?

  • To wiki PHP for example has a lot of information. Nothing prevents the web-service from being improved as well.

  • 7

    @Renan agree with you, for those who are starting, not always the terms "technical" (like those on the wiki) are easy to understand... an explanation "roughly" sometimes helps a lot of people...

  • 6

    I found it curious that no answer so far has spoken on HTTP. The explanations so far talk more about application service than web service. This makes me clear that people do not know clearly what the term is.

  • At this point I agree with you. And I saw that @Isabela spoke in a "very rude" way, which sometimes helps clarify more. I removed the -1. Really, there are things that for those who are starting it is more difficult

  • 2

    I don’t think I’m ashamed to admit I was wrong :)

  • I guess even I didn’t know, @mustache.

  • 2

    @bigown There is no requirement that a webservice has been to use HTTP. The definition of W3C only comments that "they are usually transmitted via HTTP". It is perfectly possible to define the concept of Web Service by being agnostic about how data is transmitted.

  • 2

    @Gabe But I didn’t say that either. I simplified to comment, I didn’t give an answer. But current responses leave open for any service other than web service . People are talking about something that is closer to an API than a web service, even if you don’t answer that either. That’s what I say, the vows don’t always reflect the quality. None is wrong, but none is good to define well what is.

  • @Oh mustache, yeah, yeah. But this will usually be the case when the question is about things that are much closer to an abstract concept than necessarily something concrete with a formal definition. Web Service is the type of term that is used quite freely to describe an idea, not a specific ferarmenta or technology.

  • I think I just answered that question here too in your other question: http://answall.com/questions/90374/qual-a-diff%C3%a7a-entre-web-service-e-application-service service

Show 6 more comments

6 answers

36


This is a case where maybe a picture is worth a thousand words. For example, we will use a site like pt.stackoverflow.com.

You can imagine the structure as follows:

inserir a descrição da imagem aqui

A typical web application with client and server layers. The backend can be divided into several other layers: In the example above, endpoints and API make up the layer of web services or webservices which, together with the business rules, form the application as a whole.

Your browser (the service client) contacts the application server. Much of the content is static, and can be served via simple HTTP service (images, javascript, css and the like.)

However, features such as upvote of your question need to interact with the database. These behaviors are described in the site’s business rules; and webservices exist to allow the browser to interact with these rules.

Described in this way, webservices serve as an interface between the client (in this case a browser) and the internal structure of an application (in this case the business rules.)

An example is the upvote: When I voted in favour of your question, the following endpoint was accessed:

/posts/90315/vote/2

That one endpoint belongs to a webservice who received the action. The website’s business rules, in turn, propagated the notification: Several users received a message like 'Hey, show now 7 votes instead of 6.'

This explanation is simple, and serves to give you an initial understanding of how the concept works. If you want to go deeper, here are some resources:

Message specifications: SOAP, REST; differences between these types.

Data specifications: JSON, XML

  • 2

    Excellent response!

  • Then @Onosendai, the web service would be an application (written in php, for example) that receives a request from the browser, interprets the request and returns a response in the form of XML or JSON for integration issues with various types of systems?

  • 4

    @Duds this is a description very close to reality - adjusting a little I would put it this way: 'The webservice would be the part of the application (in php or other language) that serves as an intermediary between the HTTP client and the other aspects of the application, which may include other integrated systems.'

  • Thank you @Jorgeb. !

  • Thank you @Onosendai

  • 1

    @Duds A webservice may have one or more endpoints. A good way to understand them is the name by which you expose a method of your webservice. So, imagine you have a URL like servidor.com/usuários, which lists all users of your database, and servidor.com/usuários/1, that returns the ID user = 1; the two methods are in the same Webservice, but in different endpoints.

  • @Onosendai doesn’t know how I missed a drawing like this a couple of months ago, rs! + 1!

  • @Better late than never? =)

  • 1

    @Onosendai better late than never!

  • 1

    Now I understand, thank you very much @Onosendai!

  • 1

    @Duds Always happy to help!

  • @Onosendai, I was in doubt in your image about what would be the API below the end-points. Could you clarify me?

  • @Jeffersonquesado With pleasure! I added an explanation to the image, take a look and tell me if it is clear.

  • @Onosendai sorry for the delay in responding, but I saw it just the other day and had found it clear. At least I remembered to reply. Thank you very much =]

  • @Jeffersonquesado No problem, I’m glad you liked it!

Show 10 more comments

17

My concept of Web Service is :

An app (I’ll call it API) which takes parameters and executes instructions, for example a register. An application receives the parameters "email" and "password", register in a database, and return a successful or failed response to JSON or XML.

Another application (I will call client) wants to register users in this "API", then it sends parameters by JSON or XML (in that case "email" and "password") and get success or failure response.

In short, my point of view is that a web service consists of an application being able to receive data from anywhere (as long as in the format it can interpret), process that data and send the reply to the requester.

An example I’m developing:

I have a web client registration system, which has a module I call API, where it receives parameters such as $name, $email and $password, insert them into the bank and return the reply in JSON, successfully or failed insertion.

Another web module makes the requests, sending the parameters $name, $email and $password this api, and get answers from it. Another module, this time an Android application makes the same requests, sending $name, $email and $password and getting the answers. The advantage of this is a central application, capable of processing information and being consumed by several different applications.

14

I would be the one who makes the "midfield" between two systems, I’ll give you a very simple system to see if you understand.

You have a system that we’ll call 01 where the information is. You also have a system that we will call 02 where you want to have the system information 01.

To facilitate this transport of information between the two systems, it is possible to develop a third system that will communicate with the other two, so 01 calls the web service and sends it "I want to import customers".

The Web services will take the "clients" and will send pro 02 "Insert this data in the client table".

It would be more or less in that sense that he works.

  • Would web service be the "middle ground"? It will always run on the server side, right @Isabela?

  • @Duds He will be the bridge between the two systems. How so "on the side" of the server? I did not understand your question.

  • So @Isabela, "on the side" of the server I meant if the web service will always work on the server, the web service application was made to work on servers or on client machines?

  • 2

    @Duds on servers...

  • Thank you @Isabela

  • 1

    @Duds For nothing.

Show 1 more comment

11

A common web application, the browser launches a request (request) to the server, then the server (which is expecting requests) returns information (after processing or not) to the browser. This information is in HTML that the browser uses to draw the web page.

A webservice application works similarly, but does not only return HTML and data. Normally this data is in XML or JSON format but can be any other format.

A practical application for this would be a mobile app. You do not want to transfer the whole page because it would take and consume a lot of data plan without counting that a browser has to "draw" the screen when receiving it. In a mobile application, the screens (interface) is already ready (just display) and only the data is exchanged which saves the data plan and gives more speed because the amount of data is smaller and does not have to "draw" the screen every time.

I cited the example of the mobile application, but nothing prevents other types of application use webservice as for example an electronic invoice issuing application sends notes and queries the situation through SEFAZ web service.

10

TL;DR: Webservices allow two (or more) machines to communicate via a network.

For a deeper explanation, imagine the following scenario: Your company trades dollar products, whose value fluctuates daily. It is extremely important that you have these values updated so that you make decisions that bring you better results. You can hire an intern to keep updating these values manually, or you can consume a service to provide you with this information automatically and reliably.

That service is the one webservice. You ask a question (how many five reais worth a dollar today?), and he answers you. This process, at the level of communication, is given by requests based on the HTTP protocol. There is a endpoint on a server that is always waiting for the question and, if it is done in the right way, it answers. In a quick search on google, I found a webservice that perfectly illustrates the case of the dollar quotation (and virtually all currencies), which can be accessed here.

The question (or request) should be asked correctly, otherwise the webservice will not be able to understand the request. In the case of quotation, the question should contain the two currencies you want to convert, right? Using the linked webservice above, I made the following request (in pimp terms, I entered this site):

http://www.webservicex.com/currencyconvertor.asmx/ConversionRate?FromCurrency=USD&ToCurrency=BRL

and the answer was a XML in format

<double xmlns="http://www.webserviceX.NET/">3.9818</double>

That is, through a requisition GET (the parameters are explicit in the URL), I got the information I wanted inside a XML. How did I know which parameters to use or, in other words, what is the correct format of the question? In this specific case, whoever provided the service also provided the parameters that it is waiting for for the desired information to be achieved. Try to make the request

http://www.webservicex.com/currencyconvertor.asmx/ConversionRate?FromStackOverflowCurrency=USD&ToCurrency=BRL

to see what happens.

The requisition GET is one of the four standard requests of HTTP protocol. The others are POST, PUT and DELETE. I won’t go into detail on how they all work, but you can read about the HTTP protocol here.

The XML (which is the format of the return) is a markup language, which allows manipulation of the data (or data) with ease. In the PHP, the method simplexml_load_file() allows you to read a XML, extract the data and do with it what you want. To make a file .php talk to another, you could use the Curl (which is giving me a beating this week). There is also the endless Ajax, that allows consuming services asynchronously. I particularly prefer to use the format JSON for the answers, why most of the applications that consume my services are written with the AngularJS.

There are some standards for services, in the sense of how questions and answers should be asked and constructed. In wiki on webservices, you can find a number of types of services that are based on markup languages.

You may also come across the term Restful Apis, which are basically services that are based on rest architecture. The services I build are always based on this model. There is also that great story that explains how the said architecture works.

For the icing on the cake, and the curiosity effects, Wordpress is deploying a name Restful API WP API, which will basically allow you to turn any instance of WP into a webservice. A hand on the wheel, in my opinion. =)

7

Practical example

Imagine the following situation. A company has an ERP full of complex rules and routines. Now imagine the following situation. This company saw the need to integrate it with a third party system. In this third party system it specializes in managing workflows. One of these is the purchase of pens. However, in the end, it is useless to approve if you cannot generate this purchase in ERP.

The Webservice

Well, this is where Webservice comes in. This guy proves a bridge of communication between systems. In this company context, ERP will have a service provider. This provider has a file with all the definitions of the methods of each service. For example, a purchase service can have the methods consultingCompraPorVendedor, gerarCompra, exluirCompra among others. This file is called wsdl.

Perks

The great advantage of using such form of integration (which is not the only one) is the guarantee that all information that came out and enters the ERP goes through all the business rules first, not to mention information security. Since usually the methods receive some form of authentication as user/password or token. Furthermore, in case the ERP evolves, the third party system does not necessarily need to be adjusted.

How it works?

Data exchange between systems basically works using the Http and XML/Json protocols. Where at the time of sending something called SOAP envelope is mounted and then sent to the recipient. This envelope has some data in its header, such as the address (ip/host, port) of the recipient. Already on the envelope body go the requisition data. In the mentioned example would be the purchase data of the pen.

What else?

Moreover, the webservice is also known as a form of multi-language or cross-platform integration. Since you can have, for example, an application made in java and another made in C# both tips can communicate without problems using WS technology.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.