-2

Note: This question is not an Error in code question its a general question for information on Web-Service connecting to the database.

I am new to development and I need to know why should you use web service to talk to live database? I created a page and when I took it to my boss he said you are going to need to talk to the database through web service and I just want to know what is the difference between normal data access layer and going through web service?

Simple Code
  • 558
  • 9
  • 24
  • 1
    Security. Latency. Business logic injection. Composability. Loose-coupling. Etc. – Dai Nov 13 '17 at 18:13
  • look at creating and using stored procedures as well.. also do a google search on `Linq2Sql` plenty of simple tutorials in this regard when consuming web services. – MethodMan Nov 13 '17 at 18:26
  • Thank you very much for the replies I now understand! – Simple Code Nov 14 '17 at 15:05

2 Answers2

2

why should you use web service to talk to live database?

Well, in short to provide abstraction. Without web service your client/consumer have to be smart enough to know how to deal with business model(s), interact with DB and convert the DB entities to your application model(s).

With service you are abstracting out this all stuff and thus your client has to only know how to call the service, pass the required parameters and what to get in return. That's it. It's kind a providing a simplified interface to your client (Facade Pattern)

Rahul
  • 76,197
  • 13
  • 71
  • 125
0

why should you use web service to talk to live database

The problem with this question is that "you" is not a computer and cannot talk to a database, via a web service or otherwise.

Databases need to be accessed by programs. Programs have various NFRs that affect how they are deployed, and depending on the manner of deployment, a web service may be necessary. So the answer to your question depends on what you mean by "you."

A web site may be able to access a database directly because it may exist in the same network. A Windows application, running on a remote machine, may not be on the same network, and would not be able to reach the database over the normal means-- for example, port 1433 (the default port for database connections) may not be opened on the firewall. In this situation, you can build a web service to talk to the database, and the Windows application can talk to the service over port 80 or port 443, which are usually opened.

John Wu
  • 50,556
  • 8
  • 44
  • 80