all groups > dotnet web services > april 2006 >
You're in the

dotnet web services

group:

Forcing single in-line web service execution?


Forcing single in-line web service execution? eross NO[at]SPAM cots.com
4/28/2006 8:12:56 AM
dotnet web services:
Noob here,

I am trying to manage calls from multiple clients to my web service by
only letting one execute at a time and forcing the others to wait.

Code is as follows:

------------------------------
<WebMethod()> Public Function myFunction(ByVal sXMLData As String) As
String

Static Dim objLock As New Object

SyncLock objLock

(do some stuff here)

Return sRtn

End Synclock
End Function
--------------------------------

I'm sure there's something I'm missing here, as multiple clients coming
in simultaneously will execute things at the same time. Am I missing
the point of Synclock?

Can someone point me in the right direction?

TIA
Re: Forcing single in-line web service execution? Shaun McDonnell
4/28/2006 5:10:39 PM
What you need to do is create a Singleton object and then lock that object.
That way even though users's might be calling the webservice at the same
time, the object would only allow itself to be called by one thread at a
time.

Google the "Singleton Pattern."

Shaun McDonnell

[quoted text, click to view]

Re: Forcing single in-line web service execution? Greg Young
4/29/2006 3:28:24 PM
This will only work within the same worker process ..

If the webservice instances are all runnig in the same process you could
even just lock on the type to have synchronized behavior between multiple
instances.

Generally though webservices are run in a multiple process configuration
(i.e. multiple worker processes). In this case neither of the above
solutions will work as both are scoped to the process level.

If you are running multiple worker processes on the same machine you can use
a mutex
http://msdn2.microsoft.com/en-us/library/system.threading.mutex(VS.80).aspx
to synchronize all (including between processes)

If you are running multiple processes on multiple machines, you would need
to put up a manager process to manage the synchronization between them.

Cheers,

Greg
[quoted text, click to view]

Re: Forcing single in-line web service execution? Shaun McDonnell
4/29/2006 9:09:26 PM
You are correct. A mutex would be the answer if you're web service spans
multiple w3wp.exe's.

Shaun McDonnell

[quoted text, click to view]

AddThis Social Bookmark Button