You may want to write your API. You will then call it with C# using web requests.
A very simple way to get data from your database is to switch through given endpoints in your the URL.
For instance, the following URL: http://yourserver.com/api/v1/?leaderboard/top
You may explode the URL to get the endpoints with $endpoints = explode('/', rtrim($_SERVER['QUERY_STRING'], '/'));
. In this case, $endpoints[0]
would give leaderboard.
You could then use a switch statement to handle your request.
// ...
$endpoints = explode('/', rtrim($_SERVER['QUERY_STRING'], '/'));
switch ($endpoints[0])
{
case 'leaderboard':
{
switch ($endpoints[1])
{
case 'top':
// Ask your database
$result = get_top_leaderboard();
echo json_encode($result);
break;
// case ...
}
break;
// case...
}
}
// ...
Use the same method with $_POST
to get user entries, and write them in your database. Do not forget to protect yourself from SQL injections.
In C#, perform a GET request on your API:
var responseString = await client.GetStringAsync("http://yourserver.com/api/v1/?leaderboard/top");
Keep in mind this exemple is not secured. If you want to get sensible data from your database, do not let your API unsecured with public access.