I am trying to make a Minesweeper game using a WCF service. It appears that I'm able to connect to the service from client, call methods remotely and get what they return.
The problem is, on the Service side, I use an array. Everytime a client connect to the service, the array is supposed to update itself, and it does, but everytime a client connect, the array gets reseted to 0, as if there was multiple instance of the service...
Here is the code you might want to look at:
On the service interface, IService1.cs
public interface IDemineur
{
[OperationContract]
string CreationJoueur(string Name);
[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);
// TODO: Add your service operations here
}
The Service1.svc
public class Service1 : IDemineur
{
Dictionary<int, Grille> Gamepad = new Dictionary<int, Grille>();
int[,] tableGrilles = new int[20, 3];
public string CreationJoueur(string Name)
{
string joueur = "";
for (int i = 0; i < 20; i++)
{
if (tableGrilles[i, 0] != 1)
{
tableGrilles[i, 0] = 1;
tableGrilles[i, 2] = i;
joueur = "1/" + tableGrilles[i, 2];
Gamepad.Add(i, new Grille());
break;
}
if (tableGrilles[i, 1] != 2)
{
tableGrilles[i, 1] = 2;
joueur = "2/" + tableGrilles[i, 2];
break;
}
}
return joueur;
}
Here, the point was to update the array tableGrilles. When I run the debug for the host, I can clearly see that it does update it, but whenever I connect with another client, it goes into debug mode again at my breakpoint and the array is back to 0.
Client side:
public partial class DemineurGrille : Window
{
ServiceReference1.DemineurClient leDemineur;
int noJoueur;
int noGrille;
public DemineurGrille(string name)
{
InitializeComponent();
leDemineur = new ServiceReference1.DemineurClient("*");
string noJoueurGrille = leDemineur.CreationJoueur(name);
string[] leSplit = noJoueurGrille.Split('/');
noJoueur = Convert.ToInt32(leSplit[0]);
noGrille = Convert.ToInt32(leSplit[1]);
}
Please help, that would be much appreciated...