Quantcast
Channel: Silverlight 5 forum
Viewing all articles
Browse latest Browse all 1083

static variable count 0 when call of other project

$
0
0

I have been having a problem for a long time , but so far have not got a solution and I hope you can help me .

I have a Silverlight application where I use WCF for queries to retrieve information from the database and also for the communication between client ( Duplex ) and Socket (receive and send information between my application and others).

To control Duplex , when the client accesses a specific module of my application , I link that customer to a static class that I have on my Projeto.Web ( Application start where is my WCF ) , as in the code below :

//static class and variable (list)
    public static class ncClientes
    {
        private static List<IncServicoDuplex> clientesSupRecAlarme = new List<IncServicoDuplex>();
        public static List<IncServicoDuplex> ClientesSupRecAlarme
        {
            get { return ncClientes.clientesSupRecAlarme; }
            set { ncClientes.clientesSupRecAlarme = value; }
        }
    }

//Method that include the current client
        public void VinculaCliente(string strProjeto)
        {
            //GetCallbackChannel - obter o canal de comunicação entre o serviço e o cliente - retornará a instância do canal entre o serviço e o cliente.
            IncServicoDuplex cliente = OperationContext.Current.GetCallbackChannel<IncServicoDuplex>();

            switch (strProjeto)
            {
                case "ncAlarme":
                    lock (ncClientes.ClientesSupRecAlarme)
                    {
                        ncClientes.ClientesSupRecAlarme.Add(cliente);
                    }
                    break;
            }
        }

When one client makes a change to the database, all of my others online customers who are at the module will receive this alteration by the WCF service, using the following code :

//Method that send the alteration in DataBase, per other user
        public void SupervisaoAlarmeOnline(ncAlarme objAlarme)
        {
            var varClientesAlarme = new List<IncServicoDuplex>(ncClientes.ClientesSupRecAlarme);

            foreach (var item in varClientesAlarme)
            {
                try
                {
                    item.SupervisaoAlarmeOnlineRetorno(objAlarme);
                }
                catch
                {
                    ncClientes.ClientesSupRecAlarme.Remove(item);
                }
            }
        }

//Class that receive the socket message from other application and call the Service to send to all users online
        ncServico svcOnline;
        private void RecebeMensagemSocket(IAsyncResult iar)
        {
            Socket recvSock;
            EndPoint clientEPNEW;

            try
            {
                //Get the received message.
                recvSock = (Socket)iar.AsyncState;
                EndPoint clientEP = recvSock.LocalEndPoint;

                int tamMsg = recvSock.EndReceiveFrom(iar, ref clientEP);

                string str = Encoding.Default.GetString(data, 0, tamMsg);

                svcOnline.SupervisaoAcessoOnline(listAcesso[0]);
            }
        }

My problem happens when I get some information by Socket ( class located in projeto.Web ) that creates an instance of my ServicoWCF and call the method to send the received information to clients. Apparently, my static variable is being reset when called on this side of the application.

Is there any difference on " which side " I call the service ? When I call it on WCF client side my static variable gets the correct count , but when I call it on the Socket class (that is in the same project that my WCF Services) , count is set to 0.

I hope you can help me , I tried to be as clear as possible , if there is any doubt please let me know.

Thanks in advance !


Atenciosamente, Seratti. Se esta resposta lhe ajudar "marque-a".


Viewing all articles
Browse latest Browse all 1083

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>