Answered by:
Database access in silverlight

Question
-
Hi,
I would like to know why do we use web services (or WCF etc.) when we want to connect to database in silverlight?
I know that Silverlight runs at client side but still similar to Ajax, we should be able to send request to access database. What part do web services play in database access?
Thursday, May 6, 2010 5:31 AM
Answers
-
Hi CVS,
I would like to know why do we use web services (or WCF etc.) when we want to connect to database in silverlight?
Silverlight works on client and it will interact with server side by using WebServices/WCF etc.
I know that Silverlight runs at client side but still similar to Ajax, we should be able to send request to access database. What part do web services play in database access?
AJAX will communicate with server side by using WebServices/http request(first send back your request and then server side will handle it). But, as we know, there is no specific server side for Silverlight. When use asp.net, users get/post data to server and server handle the requests. But for Silverlight, ususally, we will download a xap file only. On client, there is a Silverlight plugin, it will render the xap as desired.
Best regards,
Jonathan
Wednesday, May 12, 2010 11:49 PM -
Look at it from a security perspective and it makes sense. In order for Silverlight to have a direct connection to a database (remember Silverlight executes on the client machine, not the server) the database server needs to be publicly accessible on the Internet. This might not be a terrible issue if it's a read-only database and the Silverlight app is a viewer, but still not recommended. For Silverlight to make changes to data, the database would have to have read and write privileges given to everybody, meaning anybody on the Internet could easily connect to the database and screw stuff up.
Web services act as a middle layer. The database server is securely behind a firewall and not accessible to the Internet. The web server is accessible to the Internet but since it's on the same network as the database server it can directly connect to it. The client (Silverlight) can access the web server. So the web services are responsible for authentication and data manipulation and allow Silverlight indirect database access while keeping the data secure.
I hope this helps.
Thursday, May 13, 2010 8:48 AM
All replies
-
Web services receive the requests because we don't want the server to send us HTML, just data.
Thursday, May 6, 2010 6:05 AM -
Is it the only reason? But why web services only? Cannot it be done by implementing a class which can access database, may be using ado.net ?
I'm new to it.
Thursday, May 6, 2010 9:22 AM -
No, there is no direct support for things like ADO.NET in silverlight.
Thursday, May 6, 2010 9:25 AM -
Exactly - just like web interfaces, there is no direct connection allowed between the client and the database.
Thursday, May 6, 2010 9:33 AM -
Thanks for your replies. Yes, I understand that there is no direct connection between client and database.
Why is this connection not provided? Or why ado.net support is not provided in silverlight? Why designers took this decision of not allowing client to access database directly?
Thursday, May 6, 2010 9:42 AM -
Because it is going over the internet and using internet protocols like http.
Thursday, May 6, 2010 9:46 AM -
If I'm not wrong, we can get data in AJAX which also works over HTTP and yet not uses web services. Am I right? (Correct me if I'm wrong)
If AJAX can, why not Silevrlight ?
Thursday, May 6, 2010 9:49 AM -
It really does use web services - in Windows, it uses IIS, which acts like a generic web service.
Thursday, May 6, 2010 9:56 AM -
This thread is getting longer and longer. I did not get your last comment. How come IIS acts like a web service to provide data requested in AJAX application?
Silverlight web applications are also hosted in IIS on windows.
So why silverlight is not 'allowed' to access database directly or don't provide data access?
Thursday, May 6, 2010 9:59 AM -
I think you should read some white papers that are posted elsewhere on this site.
Thursday, May 6, 2010 10:05 AM -
Ok. I'll search for them. It would be great if you provide some links if you know any such white papers.
Also if some one else can address my questions directly, it would be helpful.
Thursday, May 6, 2010 10:08 AM -
Hi CVS,
I would like to know why do we use web services (or WCF etc.) when we want to connect to database in silverlight?
Silverlight works on client and it will interact with server side by using WebServices/WCF etc.
I know that Silverlight runs at client side but still similar to Ajax, we should be able to send request to access database. What part do web services play in database access?
AJAX will communicate with server side by using WebServices/http request(first send back your request and then server side will handle it). But, as we know, there is no specific server side for Silverlight. When use asp.net, users get/post data to server and server handle the requests. But for Silverlight, ususally, we will download a xap file only. On client, there is a Silverlight plugin, it will render the xap as desired.
Best regards,
Jonathan
Wednesday, May 12, 2010 11:49 PM -
Look at it from a security perspective and it makes sense. In order for Silverlight to have a direct connection to a database (remember Silverlight executes on the client machine, not the server) the database server needs to be publicly accessible on the Internet. This might not be a terrible issue if it's a read-only database and the Silverlight app is a viewer, but still not recommended. For Silverlight to make changes to data, the database would have to have read and write privileges given to everybody, meaning anybody on the Internet could easily connect to the database and screw stuff up.
Web services act as a middle layer. The database server is securely behind a firewall and not accessible to the Internet. The web server is accessible to the Internet but since it's on the same network as the database server it can directly connect to it. The client (Silverlight) can access the web server. So the web services are responsible for authentication and data manipulation and allow Silverlight indirect database access while keeping the data secure.
I hope this helps.
Thursday, May 13, 2010 8:48 AM