2

I have been attempting to teach myself quite a bit about silverlight, and how it all works, for the past few weeks, and I am to the point in my app development where I would like to connect up to my web server's MySQL database.

My web server is capable of running ASP.NET pages, but is Apache, and natively runs PHP (which is what I'm far more familiar with). It has a MySQL database engine, and I am very well-versed in your typical dynamic page creation with PHP and MySQL.

What I'm NOT familiar with are these "Web Services" that people keep mentioning every time I find an answer regarding the question of "how do you connect silverlight to a database?"...

So my basic question is really one of data FLOW, and where everything fits in the puzzle, and how to get it all working in this particular configuration. Most of the answers I have seen deal with IIS instead of Apache, ASP.NET instead of PHP, and MS SQL Server instead of MySQL.

Also, answers tend to start using abbreviations and acronyms without actually explaining what they stand for.

For example: What is WCF, and RIA services, and how do they fit in to the puzzle as a whole?

I suppose I'm just looking for a top-down overview of the structure of data flow on a MACRO level, not on the micro (code) level.

(Edited to add:) Also: I have done vb.net apps in the past which have used MySQLConnector.NET to pull from my web server's database remotely, but I understand that the client machine would have to be whitelisted as a remote machine, meaning I'd have to open my MYSQL server up, and make the access mask basically %.%.%.% in order for any client to connect... and that is undesirable... so if I understand things right, the web service runs on the web server, and the client sends requests to it, and the web service acts as an intermediary, grabbing the data from the database (possibly with some sort of "stored procedure" look-alike?), and passes the data on to the client... which also means all database access credentials are on the server, and not inside the (potentially hackable) client...

Do I have it right?

Also, when answering, I need to know where the access to the web services is... in the silverlight APP project code, or the silverlight WEB project code...

Jared Mark
  • 156
  • 1
  • 9
  • I found this... http://www.nikhilk.net/NET-RIA-Services-Vision-Architecture.aspx – Jared Mark Mar 21 '12 at 15:39
  • 1
    +1: Why the downvote with no comment? He obviously has spent time researching and working on his own, said where he is at, and asks specific questions. If you don't like his question let him know why... – Windle Mar 21 '12 at 15:39
  • @Windle Heh, thanks. :) I'm just trying to get a conceptual feel of it all, and far too often I find answers where either the technology discussed isn't a match, or people just assume everyone knows what XYZ and ABC means, and where those particular puzzle pieces fit in the puzzle... and I figure if I'm struggling with it, others may be as well. – Jared Mark Mar 21 '12 at 15:42
  • So here was a major sticking point for me... a "web service" is not what I thought it was... I figured it was something like an app you installed on your web server that was running in the background, kinda like the database server itself... but nope, they're just scripts... That's all... just php scripts that return formatted data. – Jared Mark Mar 22 '12 at 17:51

1 Answers1

3

I have found this wonderful tutorial that helps to explain it... http://www.designersilverlight.com/2010/05/23/php-mysql-and-silverlight-the-complete-tutorial-part-1/

Here is how I understand it all working.

There are 3 "Layers" to the process: The application, the web server, and the database.

The application calls out to the web server to execute a script file (like a normal PHP script). There script file can have normal URL variables passed to it (like script.php?foo=bar, so $foo is defined as "bar" in the script)... so you can use those URL encoded variable/value pairs to tweak your script results as you would normally with a web page.

I imagine you would have one script per TYPE of database query, with var/value pairs to tweak your results. So on your web server you would end up with numerous PHP scripts, just like you would normally for a website with different pages, and you pass variables in to those scripts to customize the results.

For example, for users, you could have a get_users.php script that would return all users...

but get_users.php?loggedin=true would get all users that are logged in currently get_users.php?loggedin=true&ingame=true would get all users that are logged in and in a game... You just script the logic and the resulting SQL query accordingly.

All of the results are encoded either with XML or JSON (Javascript Open Notation: see What is JSON and why would I use it? ) for transport to the app... the app, in effect, is reading the results of an echo of the JSON encoded stuff.

If you were to open these scripts in a web browser, the only thing you would see is a text printout of the JSON data... no web page... just data that is read by the app and then decoded in to objects.

So in effect, the silverlight app is reading a text output of a PHP script executed on your web server, and interpreting the output.

^^^^^ THIS IS THE SHORT ANSWER TO MY QUESTION. :)

To be blunt, the whole use of the terminology "web service" is misleading, and what was really leading me astray. I thought it was some sort of service or app you had to install on your web server just like PHPMyAdmin or something.

Community
  • 1
  • 1
Jared Mark
  • 156
  • 1
  • 9
  • 1
    Glad you found your answer! One quick thing to make sure you have a good grip on the "Web service" idea though: In a more generic sense, the web service could be implemented with anything (not just PHP). For example, say you find a web service online that you wanted to use. As long as they provide an API for how to call their methods (eg a WSDL for a SOAP web service) you don't care if they implemented in Java, C#, whatever as long as you get your XML or JSON back. – Windle Mar 30 '12 at 16:20