Take the 2-minute tour ×

I have been asked to load test an external webservice hosted by our client.

Basically to send multiple web requests to the service and time how long it takes for the service to process them all. To try and simulate multiple different users hitting the web service from different machines. The test will be to check that the webservice can handle this an to basically give the client some metrics and examples....e.g how long its takes 50 requests to respond.

I am aware that this could be achieved by using a tool like SoapUI/LoadUI.

What I want to know is there anyway I can write a load test using C#?

Currently I have something along the lines of the following:

    public void TestService50Requests()
        List<WebRequest> requests = CreateMultipleRequests(50); //Creates web request objects

        string timeSpan = TimeMultipleRequests(requests);

        Console.WriteLine("50 Requests runtime: " + timeSpan);

    private void TimeMultipleRequests(List<WebRequest> requests)
       var stopWatch = new Stopwatch();

       foreach (var request in requests)

       var timeSpan = stopWatch.Elapsed;
       return String.Format("{0:00} hours, {1:00} minutes, {2:00} seconds, {3:00} milliseconds", timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds, timeSpan.Milliseconds / 10);           

I assume there is a better way to do this? Any suggestions for improvements or is this completely wrong?

share|improve this question
Is there a reason for not making multiple requests at once? –  Blachshma Jan 31 '13 at 10:12
Why not use Soap UI? –  amaters Jan 31 '13 at 10:13
What you are doing is not a Unit Test. I have edited the title and tags accordingly. –  w0lf Jan 31 '13 at 10:15
@Blachshma no, apart from the fact that I am trying to simulate multiple different users hitting the service. If that makes sense –  Riain McAtamney Jan 31 '13 at 10:16
@amaters I can use SoapUI but I just want to try and achieve this via C# also. –  Riain McAtamney Jan 31 '13 at 10:17

2 Answers 2

up vote 2 down vote accepted

It really depends on what you are trying to test. Load testing can be used to stress (how many concurrent users it takes to break the system) or soak (medium load for an extended time period) the system. Your code does not send any concurrent requests to the system so it cannot be considered a good test that would mimic the real behavior of users.

There are good tools to accomplish these, but they can be costly. If you have Visual Studio Ultimate at your disposal, the load testing tools included are pretty good. You can also look at WAPT, which is a tool that will do a similar thing.

So, I would go back to the person that gave you the requirement and ask what specifically needs to be tested. Is it number of concurrent users the system can handle, no memory leaks, system availability, or performance?

share|improve this answer

To present another alternative to SoapUI - I would use JMeter rather than trying to do it in C#.

From the front page:

Apache JMeter features include:

  • Can load and performance test many different server types:

    • SOAP
share|improve this answer
thanks - I am aware that there are tools that are probably better for the job of load testing the service but I just want to try this via C# –  Riain McAtamney Jan 31 '13 at 10:18

Your Answer


