ASP.NET Server Competition

3

I have a Silverlight application, which accesses a service in WCF. In this application I have a SaveNoteFiscal () method. This method calls a ValidateNoteFiscal method that checks whether an invoice with the reported number and series already exists. This SaveNoteFiscal method is very large because it performs several routines.

The customer clicked this button several times, and 6 notes with the same number were posted to the system; the scenario was this I believe, because there would be no other way to duplicate these notes if there is validation.

I believe that ASP.NET answers requests in parallel, which makes sense to me because there may be multiple concurrent users and the server needs to attend all at once.

As for my problem in Silverlight, I have already tried to disable the button when it is clicked and enable in the callback return, but it has not worked.

public void Salvar()
{
  btnSalvar.IsEnabled = false; 
  NotaFiscalClient objSvcNotaFiscal = new NotaFiscalClient();
  objSvcNotaFiscal.SalvarNotaFiscalAsync(this.objNotaFiscal);
  objSvcNotaFiscal.SalvarNotaFiscalCompleted += (s, e) =>
       btnSalvar.IsEnabled = true;         
  };
}
    
asked by anonymous 06.06.2016 / 19:48

1 answer

0

Yes, HTTP requests occur in parallel.

You can block this from occurring in a variety of ways ...

First start blocking the user from pressing the button several times, before a request is completed ... (just put a simple LOCK in the Save method you should solve!)

Regarding multiple users generating the note with the same number, you will have to do the treatment in the back end (WCF), the easiest is also through the LOCK , but only if you have a single server running a single WCF process will work!

If the webservice is running through multiple concurrent processes, you can use a Mutex to ensure single access to a snippet of code (or the entire method, if any)

Remembering both the LOCK statement, and the use of the Mutex class, you need to create a logic that only allows one note at a time to enter the process according to the note number and not generalized, otherwise you will have a queue of notes to process, being one at a time, causing slowness to the users.

If your back-end (WCF) is distributed (on multiple servers, load balancing, failover, etc.) you will not succeed only with a LOCK / MUTEX, you will need to create a system where there will be one server to control locks and then lock it, or better, you can do this using a database (SQL) or even Redis. In a better solution for this scenario would be to implement a messaging system (MSMQ or Redis) where only one host would be responsible for processing the notes, and the other just performing the other tasks ...

    
10.01.2017 / 05:23