Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 650677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:04:45+00:00 2026-05-13T22:04:45+00:00

I have an asmx web service that should only be allowed to respond to

  • 0

I have an asmx web service that should only be allowed to respond to 1 client at once.

In otherwords if the service is getting called by client A, and server B calls, I would like B to pend until A is finished then B can get serviced.

If this is too complicated then at bare minimum calls from B should fail with a user defined error during the time A is engaging the service.

The reason is that the service relies heavily on IO operations and XML serialization, so it is crucial that the service does not get called simultaneously by more than 1 client.

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T22:04:45+00:00Added an answer on May 13, 2026 at 10:04 pm
    static object _LockObject = new object();
    
    void WebServiceCall()
    {
        lock(_LockObject)
        {
            // Do work...
        }
    }
    

    Create a static object that you call lock() on. The lock() statement will prevent other calls from executing the code inside until the first execution that got the lock completes.

    Note that depending on your timeout settings B might fail with a timeout depending on how long A takes to complete.

    Update: Yes you can use the Monitor class in place of lock(). You could use the Monitor.TryEnter() method to check if the object is already locked or not (ie: if you wanted to return an error instead of waiting).

    More details:

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

    A lock statement of the form

    lock (x) ...
    

    where x is an expression of a reference-type, is precisely equivalent to

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

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

    Use Enter to acquire the Monitor on the object passed as the parameter. If another thread has executed an Enter on the object, but has not yet executed the corresponding Exit, the current thread will block until the other thread releases the object.

    So it’s just by design that the code knows to block and not skip. You could skip if you wanted by using the Monitor.TryEnter() method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web service that contains 2 asmx files (public.asmx and private.asmx). On
I have a .NET web service (using asmx...have not upgraded to WCF yet) that
I have a Java client that consumes SharePoint 2010 standard web services (sitedata.asmx, permissions.asmx,
I have some web methods in an asmx web service that currently look like
I have a asmx web-service that returns a list of countries for a continent.
Business case: I have a ASMX web service that copies/deletes/downloads files from some remote
I developed a asp.net 2.0 web service (.asmx), now my client said that there
I have a web service, .asmx that when consumed gives a response in the
I have an ASMX web service that is referenced by my silverlight front end,
Why is that Web Service files (.asmx) have their code-behind placed in app_code folder

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.