There are several explanations on the internet, I will try to answer in a less technical way and show when to use, because we learn faster with the need. So first I’m going to impose ways to need certain features but that are not the best ways to do and the need ends up needing a web service.
Web service
When to use?
I want to create a news site on the internet, my target audience are Android users, iOS and website. My database needs to be unique and shared with these three platforms.
Initially you would think I can make Android communicate directly with the database and search for the necessary information, for this would have to create functions of search, insertion, and delete.
For iOS would also need these functions could communicate direct too, and my website also need this.
Interesting each platform would have its own way of communicating with the database.
Why not do it?
Most importantly, security, you can’t communicate directly like this with a database, it would be an unnecessary risk.
Another point that is taken into consideration is that if you’ve noticed everyone has functions in common, they all search for the same data, they make the same types of inserts and entries in the database, then why can’t I create a "face" that is on the side of the database, This guy does all communications for you with the database, the Android or iOS do not request the same thing? then I only do once certain function and make available at an internet address, example
www.meuwebservice.com/pegar_todos_os_posts_do_dia.php
. Now when Android and iOS want to get the "news posts" from the database it asks the web service a service. The Web service only makes the posts available to him no matter who requested it is Android, iOS, website, desktop application.
To finish on Web service, it is nothing more than a program that provides services via internet, for different platforms indifferent to the programming language used, it shares resources between different platforms.
SOAP AND REST
But wait, the Android language is in JAVA, iOS is in Objective-C and my website is in Python, and still my web service is in PHP. One speaks English, another Portuguese, and another Chinese. A mixture of rsrs. How can I solve this? well, we need an intermediate language that everyone should understand. But for this we need to define a communication protocol (standard).
Then enter the SOAP or REST communication protocols.
SOAP the oldest, is a message transfer protocol in format XML. The messages that will be exchanged have a very strict standard and stuck to XML.
REST is a more flexible protocol, you do not get tied to XML, you can create messages like plain text, message with formats JSON or even XML.
So how does this communication work?
Android makes a request for a web service, he wants all the news posts of the day, the web service, then recovers the posts of the day, transforms the set of posts into an XML file, and sends to Android that XML file, Android gets the XML file, It can read XML, then read the data within XML and convert the data to manipulate in its native language. IOS also wants the same kind of data, asks the web service, the web service sends the same XML, iOS also know how to read XML, so it decodes to manipulate in its native language. The same thing for a website, or even a desktop application made in Delphi, all receive the same XML, everyone knows how to read XML, and convert to their native language, and the web service performs a single function for all platforms.
Remember that they, only know how to read XML because there is a pattern when XML was created, example, within the body of the XML file, there must be a piece that relates to the context of the communication, this part must be at the beginning of the file and is called header, and a portion of the file must contain the data the client requested, and it will be called body. This goes for SOAP where the file has a hard pattern when being created.
More about Web service.
More about SOAP AND REST.
Very good answer, really was missing this so I can understand... A less technical answer. So following what you said, I can’t see a scenario in the example I mentioned where I should use webservice, I believe it’s not necessary yet
– felipe.rce
yes vc would need a web service vc said that users need to register an account when entering the application, the login data then must be stored on a server with a database, You need a webservice to receive the account data and save in the database. Ai when the user is logging into the application he asks the web service to authenticate
– Skywalker
But for login, it is not better to consult direct from the bank?
– felipe.rce
The best explanation I’ve ever found
– user70112
Best answer!! Saving lives in 2018 rsrs. Thank you!
– Maycon Silva