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. =)
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?
– Renan Gomes
To
wiki
PHP for example has a lot of information. Nothing prevents the web-service from being improved as well.– Wallace Maxters
@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...
– Isa
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.
– Maniero
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
– Wallace Maxters
I don’t think I’m ashamed to admit I was wrong :)
– Wallace Maxters
I guess even I didn’t know, @mustache.
– Wallace Maxters
@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.
– Gabe
@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.
– Maniero
@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.
– Gabe
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
– Caffé