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

  • Home
  • SEARCH
  • 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 759991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:39:48+00:00 2026-05-14T15:39:48+00:00

i am writing a program to test WCF service performance in high concurrency circumstance.

  • 0

i am writing a program to test WCF service performance in high concurrency circumstance.

On client side, i start many threads to call a WCF service function which returns a long list of data object.

On server side, in that function called by my client, i need to know the number of clients calling the function.

For doing that, i set a counter variable. In the beginning of the function, i add the counter by 1, but how can i decrease it after the function has returned the result?

int clientCount=0;
public DataObject[] GetData()
{
     Interlocked.Increment(ref clientCount);
     List<DataObject> result = MockDb.GetData();
     return result.ToArray();
     Interlocked.Decrement(ref clientCount);    //can't run to here...
}

i have seen a way in c++.

Create a new class named counter.

In the constructor of the counter class, increase the variable.
And decrease it in the destructor.

In the function, make a counter object so that its constructor will be called.
And after the function returns, its destructor will be called.

Like this:

class counter
{
public:
    counter(){++clientCount;  /* not simply like this, need to be atomic*/}
    ~counter(){--clientCount;  /* not simply like this, need to be atomic*/}
};

...
myfunction()
{
    counter c;
    //do something
    return something;
}

In c# i think i can do so with the following codes, but not for sure.

public class Service1 : IService1
{
    static int clientCount = 0;

    private class ClientCounter : IDisposable
    {
        public ClientCounter()
        {
            Interlocked.Increment(ref clientCount);
        }

        public void Dispose()
        {
            Interlocked.Decrement(ref clientCount);
        }
    }

    public DataObject[] GetData()
    {
        using (ClientCounter counter = new ClientCounter())
        {
            List<DataObject> result = MockDb.GetData();
            return result.ToArray();
        }
    }
}

i write a counter class implement the IDisposable interface.
And put my function codes into a using block.
But it seems that it doesn’t work so good.
No matter how many threads i start, the clientCount variable is far less than the threads number.

Any advise would be appreciated.

  • 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-14T15:39:48+00:00Added an answer on May 14, 2026 at 3:39 pm

    Have a look at the various layers WCF uses. You can plug into one of them.

    For example add a IDispatchMessageInspector to your EndpointBehavior:

    public class ConsoleOutputMessageInspector : IDispatchMessageInspector
    {
        public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
        {
             Console.WriteLine("Starting call");
             // count++ here
             return null;
        }
    
        public void BeforeSendReply(ref Message reply, object correlationState)
        {
            // count-- here
            Console.WriteLine("Returning");
        }
    }
    

    See more here: http://weblogs.asp.net/paolopia/archive/2007/08/23/writing-a-wcf-message-inspector.aspx

    Have a look how to extend WCF here:
    http://msdn.microsoft.com/en-us/magazine/cc163302.aspx#S6

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

Sidebar

Related Questions

I am writing a test program to copy some file in Application data folder
I'm writing a program that sends an email out at a client's specific local
I am writing a test program with Ruby and ActiveRecord, and it reads a
I am writing a test program to understand vector 's better. In one of
This question might be a little specific but the test program im writing uses
I am writing an automated test program using curl-loader, to send calculated requests to
I'm writing a simple test program to pass multidimensional arrays. I've been struggling to
I am writing a small test program that gives the following xml file as
Okay, so I'm writing a test program to send a vector of objects from
I am writing a program to leak memory( main memory ) to test how

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.