webservice concurrency

P

Paolo Liverani

Hi,
I am writing a Web Service and I am having problems managing
concurrency of web methods.
Actually, I am interested in avoiding concurrency at all.
How can I ensure that only one web method is running at a given time?

I tried to wrap every webmethod inside an Application.Lock() /
Application.Unlock() pair, but it doesn't seem to be working.

The problem I am trying to solve is the following: on entry,
every web method reads in a status file, performs some computations,
and then writes down the file to disk. I must be sure that access to
this file is mutually exclusive.

Thank you in advance for your help
 
M

[MSFT]

Hi Paolo,

I think there are two approuch to achieve this:

1. Instead of a text file, you may consider use a database. ADO.NET will
take care the concurrency issue.
2. Create a type library for read/write the status file. In your web method
call the type library. In the type library, you can consider
ReaderWriterLock Class to control the read/write. For more inforamtion
about it, you can refer to:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfSystemThreadingReaderWriterLockClassTopic.asp

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
P

Paolo Liverani

Ok, thank you Luke.
That's not exactly what I was looking for but if there is no other solution
I'll for the first one.
-Paolo
 
D

Dilton McGowan II

Paolo Liverani said:
Hi,
I am writing a Web Service and I am having problems managing
concurrency of web methods.
Actually, I am interested in avoiding concurrency at all.
How can I ensure that only one web method is running at a given time?

Static constructor for the whole web service class? This is not something I
recommend from a performance angle.
I tried to wrap every webmethod inside an Application.Lock() /
Application.Unlock() pair, but it doesn't seem to be working.

The problem I am trying to solve is the following: on entry,
every web method reads in a status file, performs some computations,
and then writes down the file to disk. I must be sure that access to
this file is mutually exclusive.

Define a static class global object and lock( it ) ? This is somewhat
better, at least it allows some concurrency.

Side note is that if you are going to do something in all or many methods
creating a custom attribute class can be useful.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,231
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top