Load Testing Web Service Using Visual Studio

Introduction

Web Services are more commonly developed and used to expose the APIs for other systems to consume. A number of external systems consume the web services on a very frequent basis.

Load testing is a good way to test how the web service behaves under the heavy load before going live. The load test results help in many ways to improve the performance of the web service.

Sample Web Service

I came across a nice and simple calculator web service designed to perform basic mathematical operations – Add, Divide, Multiply, Subtract.

Calculator web service: http://www.dneonline.com/calculator.asmx

Load Testing Web Service

We will use this web service to carry out the load testing.

Prerequisites

You will need,

  1. Visual Studio Enterprise - https://www.visualstudio.com/vs/enterprise/
  2. Visual Studio Team Services account - https://www.visualstudio.com/team-services/

Load Test Project in Visual Studio

  1. Open Visual Studio.
  2. File -> New Project -> Test -> Web Performance and Load Test Project.

    Load Testing Web Service
  1. By default, the project template will have WebTest1.webtest created for you. The web test is used to test the single page.
  2. Right click the WebTest1 node and select Add Request.

    Load Testing Web Service
  1. Now, right click the http://localhost/ node and select Properties.

    Load Testing Web Service
  1. In the Properties window, enter the URL of the web service to test.

    Load Testing Web Service
  1. Click “Run Test”.

    Load Testing Web Service
  1. The Run test should pass as below.

    Load Testing Web Service

Configure web test to test specific web method

  1. Open the web service (for e.g. http://www.dneonline.com/calculator.asmx) in a browser.
  2. Select the web method you want to test (e.g. Add).
  3. See the SOAP message. It contains SOAPAction.

    Load Testing Web Service
  1. In the web test, right click and select “Add Header”.

    Load Testing Web Service
  1. In Name property, type SOAPAction.
  2. In the Value property, type the value of SOAPAction (for e.g. http://tempuri.org/Add).

    Load Testing Web Service
  1. Choose String Body node and in Content Type property enter a value of text/XML.
  2. In the String Body property, paste the contents of XML portion of the SOAP request from the Web service description page.

    E.g
    1. <?xml version="1.0" encoding="utf-8"?>  
    2. <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">  
    3.   <soap:Body>  
    4.     <Add xmlns="http://tempuri.org/">  
    5.       <intA>int</intA>  
    6.       <intB>int</intB>  
    7.     </Add>  
    8.   </soap:Body>  
    9. </soap:Envelope>  
  1. Replace int or string content placeholders with the actual values you want to test

    E.g.
    1. <?xml version="1.0" encoding="utf-8"?>  
    2. <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">  
    3.   <soap:Body>  
    4.     <Add xmlns="http://tempuri.org/">  
    5.       <intA>8</intA>  
    6.       <intB>5</intB>  
    7.     </Add>  
    8.   </soap:Body>  
    9. </soap:Envelope>  
  1. The final configuration will display as -

    Load Testing Web Service
  1. Right click Web service request and select Add URL QueryString Parameter.

    Load Testing Web Service
  1. Enter the name as "op" and the value as "Add". This identifies the Web service operation to perform.

    Load Testing Web Service
  1. Click "Run" to test the web method.

    Load Testing Web Service

Configure Load Test

We will now configure the load test.

  1. To add the load test to the solution, right click Solution, select Add -> Load Test.

    Load Testing Web Service

    This will run through a wizard to setup the load test.
  1. If you have Visual Studio Team Services account, select “Cloud-based Load Test with Visual Studio Team Services”, else select “On-premise Load Test”.

    Load Testing Web Service
  1. Click "Next".
  2. Select Azuredata center nearby your location or select Default.

    Load Testing Web Service

  3. Provide the load test duration.

    Load Testing Web Service

  4. Click "Next".
  5. Enter Scenario name.

    Load Testing Web Service

  6. Click "Next".
  7. Specify the number of concurrent users. Default value is 25 users.

    Load Testing Web Service
  1. Click "Next".
  2. Select the test mix model.

    Load Testing Web Service

  3. Click "Next".
  4. Click "Add" button.
  5. Select the web test created before.

    Load Testing Web Service

  6. Click "OK".
  7. Click "Next".
  8. In the final wizard step, you can select the browsers and distribute the load to browsers based on your prediction of end user environment.
  9. Click "Add" to add new browser type.

    Load Testing Web Service

  10. Click "Finish".
  11. The load test will be created as below.

    Load Testing Web Service
  1. Click "Run".
  2. The result will be displayed as below.

    Load Testing Web Service

X

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now