How to ensure that the asmx web service is called only once at a time?

I have an asmx web service that is allowed to respond to only one client.

In other words, if the service is called by client A and calls to server B, I would like B to postpone until A is completed, then B can get the service.

If this is too complicated, then with minimal minimum calls from B, a user error should fail for the time when A enters the service.

The reason is that the service is heavily dependent on XML I / O and serialization, so it is imperative that the service is not invoked by more than one client at a time.

Thanks in advance

+5
source share
4
static object _LockObject = new object();

void WebServiceCall()
{
    lock(_LockObject)
    {
        // Do work...
    }
}

, lock(). lock() , , .

, B - , A.

: , lock() Monitor. Monitor.TryEnter(), , (: ).

:

http://msdn.microsoft.com/en-us/library/aa664735(VS.71).aspx:

lock (x) ...

x - ,

System.Threading.Monitor.Enter(x);
try {
   ...
}
finally {
   System.Threading.Monitor.Exit(x);
}

http://msdn.microsoft.com/en-us/library/de0542zz.aspx:

Enter, , . Enter , Exit, , .

, . , , Monitor.TryEnter().

+4

, .net, , , "" , Java - .

, concurrency... , , , , , , , ). , , .

- (, Java) , , , , .

+2

, , - .

. , , - .

, . ( , ).

. - , , , , (, GUID).

+2

, , . , Linux- APT :

, , .

Similarly, you can create a file in the root of the virtual host. When the client is connected, block this file, I will write something in it. When it finishes, make the file empty. Before you try to block it, try to see if there is anything inside. If so, return the error message to the client.

0
source

All Articles