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
We will use this web service to carry out the load testing.
Prerequisites
You will need,
- Visual Studio Enterprise - https://www.visualstudio.com/vs/enterprise/
- Visual Studio Team Services account - https://www.visualstudio.com/team-services/
Load Test Project in Visual Studio
- Open Visual Studio.
- File -> New Project -> Test -> Web Performance and Load Test Project.
- By default, the project template will have WebTest1.webtest created for you. The web test is used to test the single page.
- Right click the WebTest1 node and select Add Request.
- Now, right click the http://localhost/ node and select Properties.
- In the Properties window, enter the URL of the web service to test.
- Click “Run Test”.
- The Run test should pass as below.
Configure web test to test specific web method
- Open the web service (for e.g. http://www.dneonline.com/calculator.asmx) in a browser.
- Select the web method you want to test (e.g. Add).
- See the SOAP message. It contains SOAPAction.
- In the web test, right click and select “Add Header”.
- In Name property, type SOAPAction.
- In the Value property, type the value of SOAPAction (for e.g. http://tempuri.org/Add).
- Choose String Body node and in Content Type property enter a value of text/XML.
- In the String Body property, paste the contents of XML portion of the SOAP request from the Web service description page.
E.g
- <?xml version="1.0" encoding="utf-8"?>
- <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/">
- <soap:Body>
- <Add xmlns="http://tempuri.org/">
- <intA>int</intA>
- <intB>int</intB>
- </Add>
- </soap:Body>
- </soap:Envelope>
- Replace int or string content placeholders with the actual values you want to test
E.g.
- <?xml version="1.0" encoding="utf-8"?>
- <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/">
- <soap:Body>
- <Add xmlns="http://tempuri.org/">
- <intA>8</intA>
- <intB>5</intB>
- </Add>
- </soap:Body>
- </soap:Envelope>
- The final configuration will display as -
- Right click Web service request and select Add URL QueryString Parameter.
- Enter the name as "op" and the value as "Add". This identifies the Web service operation to perform.
- Click "Run" to test the web method.
Configure Load Test
We will now configure the load test.
- To add the load test to the solution, right click Solution, select Add -> Load Test.
This will run through a wizard to setup the load test.
- If you have Visual Studio Team Services account, select “Cloud-based Load Test with Visual Studio Team Services”, else select “On-premise Load Test”.
- Click "Next".
- Select Azuredata center nearby your location or select Default.
- Provide the load test duration.
- Click "Next".
- Enter Scenario name.
- Click "Next".
- Specify the number of concurrent users. Default value is 25 users.
- Click "Next".
- Select the test mix model.
- Click "Next".
- Click "Add" button.
- Select the web test created before.
- Click "OK".
- Click "Next".
- In the final wizard step, you can select the browsers and distribute the load to browsers based on your prediction of end user environment.
- Click "Add" to add new browser type.
- Click "Finish".
- The load test will be created as below.
- Click "Run".
- The result will be displayed as below.