Purpose of a WebService

2

Well, I always see on the internet or I even hear friends talking about WebServices , I've read some things related to the subject but I still can not understand it very well. I know that with WebService I can do the interaction of multiple systems. But would not it be easier for me to connect all these systems to just one database and get all the data from it?

    
asked by anonymous 06.07.2015 / 18:35

1 answer

2
  

But would not it be easier for me to connect all these systems to just one database and get all the data from it?

No.

The reason is that if you give access to the database, your security, business rules and encapsulation are compromised.

Imagine that site A is a carrier and site B is a merchandise sales company. Customers access website B to make purchases and the company website B talks to website A through a webservice to schedule delivery of goods and to obtain the cost of freight to be charged to the user.

But supposing that site A opens access to the database for company B. In this case company B could gain access to data from other customers of the carrier, it could register, change and destroy information of which she does not own, including other customers of the carrier. The result would be chaos.

There is the question of the business rules of company A. With direct access to the database by company B, who in company A can guarantee that the process in company B will not register deliveries in unmet cities? Once company B has access to the A database, all of A's business rules have been circumvented.

In addition, let's assume that to calculate freight, company A needs to collect data from 27 different tables. Why does company B need to know this if the only thing they want is the value of freight? Company B does not want to know how the price of gasoline in different regions of the country and how the toll costs affect the price of freight, as this is the responsibility of company A. What company B wants to know is just what would be the freight price. This price is something that the webservice of company A can inform, and what is behind this webservice is the problem and responsibility of company A. But if direct access to the database is used instead, then company B would need to execute all these processes in the 27 tables of company A, which should not be their responsibility.

In addition, even if Company B is well-behaved, Company A will not be able to make changes to its database easily without breaking things for Company B and all other customers it has access to its bank of data. If someone invades the company B website, the company A database would also be compromised and along with it, that of all other A clients.

The best thing is that company A makes available a webservice publishing the operations to be performed. In this way, the implementation of the database is restricted to company A. If it wants to make changes in the database to use information on road drilling to calculate the freight, it is enough for them to make some changes in the implementation of the service to guarantee the compatibility and company B does not even need to know there has been some kind of change because it's really not their problem.

In addition, with webservice, you ensure that business rules will be respected and that company B will only have access to what interests them the way they should. If company B tries to register a delivery in a city that is not met, webservice returns an error. With webservice you can also do validations and checks (including login / password). In addition, company B does not need to know (and will not even want to know) how it does to extract and aggregate data from 27 different tables to calculate freight, as this is the responsibility of company A and company B has nothing to do with that.

And not everything is limited to the database, imagine that in the calculation of the route for delivery in company A there is a process that depends on the generation and manipulation of some files. So, would you open the file system for the others too?

    
06.07.2015 / 23:32