Поделиться через


How To: Use ACT to Test Web Services Performance

 

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

patterns & practices Developer Center

Improving .NET Application Performance and Scalability

J.D. Meier, Srinath Vasireddy, Ashish Babbar, and Alex Mackman
Microsoft Corporation

May 2004

Related Links

Home Page for Improving .NET Application Performance and Scalability

Chapter 15, Measuring .NET Application Performance

Chapter 16, Testing .NET Application Performance

How To: Use ACT to Test Web Services Performance

Send feedback to Scale@microsoft.com

patterns & practices Library

Summary: Microsoft® Application Center Test (ACT) does not directly support the testing of Web services, so you must manually modify your test scripts to make the tool work correctly. This How To walks you through the creation of an ACT test script file that you can use to load test a Web service.

Contents

Summary of Steps
Step 1. Create an Empty ACT Test
Step 2. Create the SOAP Request
Step 3. Copy the SOAP Envelope to the Test Script File
Step 4. Modify the SOAP Envelope
Step 5. Add Request Headers to the Test File
Step 6. Add Send Request to Complete the Test File
Final Test Script
Sample: Simple Web Service
.NET Framework Version 1.1 Considerations
Additional Resources

Applies To

  • Microsoft Application Center Test (ACT). This tool is included with Microsoft Visual Studio®.NET Enterprise Developer and Enterprise Architect Editions.
  • Microsoft .NET Framework versions 1.0 and 1.1.

Overview

ACT is designed for stress testing Web servers and analyzing performance and scalability problems with Web applications. Visual Studio .NET Enterprise Developer and Enterprise Architect Editions include ACT. You can use ACT directly within the integrated development environment (IDE), though this method provides limited project configuration options. Full options are available only when you use the stand-alone ACT application.

ACT does not directly support the testing of Web services, so you must manually modify your test scripts to make the tool work correctly. This How To walks you through the creation of an ACT test script file that you can use to load test a Web service. The sample code for the Web service used in this example is available in "Sample: Simple Web Service" later in this How To.

Summary of Steps

This How To includes the following steps:

  1. Create an empty ACT test.
  2. Create the SOAP request.
  3. Copy the SOAP envelope to the test script file.
  4. Modify the SOAP envelope.
  5. Add request headers to the test file.
  6. Add Send Request to complete the test file.

Step 1. Create an Empty ACT Test

In this step, you create an empty ACT test named ACTTest.

To create an empty test

  1. Start ACT. In the Actions dialog box, click New Test.
  2. In the Welcome dialog box, click Next.
  3. In the Test Source dialog box, click Create an empty test, and then click Next.
  4. Click Next.
  5. In the Test name field, type a name for the test (in this case, ACTTest).
  6. Click Next, and then click Finish.

Step 2. Create the SOAP Request

Invoke the Web service from Microsoft Internet Explorer® by entering the path of the Web service to be tested. Then select the Web method you want to test. A Web service Help page is displayed that contains the following sample SOAP request and response.

POST /HelloTest/WS/ACTSampleWS.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/Hello"

<?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="https://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <Hello xmlns="http://tempuri.org/" />
  </soap:Body>
</soap:Envelope>

Step 3. Copy the SOAP Envelope to the Test Script File

Copy the entire SOAP envelope from the browser window to the Clipboard, and then paste it into your test script as follows.

<?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="https://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <Hello xmlns="http://tempuri.org/" />
  </soap:Body>
</soap:Envelope>

Step 4. Modify the SOAP Envelope

You need to modify the SOAP envelope in two ways:

  • Replace double quotation marks with"& chr(34) &" in the copied SOAP envelope.
  • Convert the SOAP envelope to a request body.

Replace Double Quotation Marks with "& chr(34) &" in the Copied SOAP Envelope

You need to replace the double quotation marks with "& chr(34) &". You can use the ACT Replace menu item to automate this task.

To replace double quotation marks by using ACT

  1. On the Edit menu, click Replace.

  2. In the Findwhat edit box, add one double quotation mark ( " ).

  3. In the Replacewith edit box, type "& chr(34) & ", including quotation marks on each side.

  4. Click Replace All.

    Note that there is no undo option for this action.

Convert the SOAP Envelope to a Request Body

You need to add Body = " to the first line (make sure that there are no spaces after the double quotation marks) and Body = Body & " to all of the following lines of the modified SOAP envelope. Also, add a quotation mark at the end of each line of the SOAP request.

Sample SOAP Envelope

After you've made these two modifications, the SOAP envelope looks like the following.

Body = "<?xml version="&chr(34)&"1.0"&chr(34)&" encoding="&chr(34)&"utf-8"&chr(34)&"?>"
Body = Body & "<soap:Envelope xmlns:xsi="&chr(34)&"http://www.w3.org/2001/XMLSchema-instance"&chr(34)&" xmlns:xsd="&chr(34)&"http://www.w3.org/2001/XMLSchema"&chr(34)&" xmlns:soap="&chr(34)&"https://schemas.xmlsoap.org/soap/envelope/"&chr(34)&">"
Body = Body & "<soap:Body>"
Body = Body & "<Hello xmlns="&chr(34)&"http://tempuri.org/"&chr(34)&" />"
Body = Body & "</soap:Body>"
Body = Body & "</soap:Envelope>"

Step 5. Add Request Headers to the Test File

Add the following code to the beginning of the test script. Place this code immediately before the SOAP request you pasted into the test.

Dim oConnection
Dim oRequest
Dim oRepsonse
set oConnection = Test.CreateConnection("<Web Server Name Here>", 80, false)
set oRequest = Test.CreateRequest

oRequest.Path = "<Web Service Path Here>"
oRequest.Verb = "POST"
oRequest.HTTPVersion = "HTTP/1.1"

oRequest.Headers.RemoveAll
oRequest.Headers.Add "Host", "(automatic)"
oRequest.Headers.Add "SOAPAction", "<Web Service Namespace here>"
oRequest.Headers.Add "Content-Type", "text/xml; charset=utf-8"
oRequest.Headers.Add "Content-Length", "(automatic)"

Note   You must replace <Web Service Path Here> with your Web service path, and you must replace <Web Service Namespace here> with your Web service namespace.

Obtaining the Web Service Path

Obtain the Web service path from the generated output that is displayed in the browser. Sample output is shown here. Use the Web service path from the POST line of the request.

POST /HelloTest/WS/ACTSampleWS.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/Hello"

The path for this sample is /HelloTest/WS/ACTSampleWS.asmx.

Obtaining the Web Service Namespace

Obtain the Web service namespace from the generated output displayed in the browser. Copy the Web service path from the SOAPAction: line of the request.

oRequest.Headers.Add "SOAPAction", "http://tempuri.org/Hello"

The path for this sample is http://tempuri.org/Hello.

Step 6. Add Send Request to Complete the Test File

Add the following code to send the request to the end of the script file.

oRequest.Body = Body
Set oResponse = oConnection.Send(oRequest)

Final Test Script

The following example shows a test script after the modifications discussed in this How To have been applied. This script is suitable for testing a Web service.

Dim oConnection
Dim oRequest
Dim oRepsonse
set oConnection = Test.CreateConnection("localhost", 80, false)
set oRequest = Test.CreateRequest

 oRequest.Path = "/HelloTest/WS/ACTSampleWs.asmx"
 oRequest.Verb = "POST"
 oRequest.HTTPVersion = "HTTP/1.1"

 oRequest.Headers.RemoveAll
 oRequest.Headers.Add "Host", "(automatic)"
 oRequest.Headers.Add "SOAPAction", "http://tempuri.org/Hello"
 oRequest.Headers.Add "Content-Type", "text/xml; charset=utf-8"
 oRequest.Headers.Add "Content-Length", "(automatic)"

Body = "<?xml version="&chr(34)&"1.0"&chr(34)&" encoding="&chr(34)&"utf-8"&chr(34)&"?>"
Body = Body & "<soap:Envelope xmlns:xsi="&chr(34)&"http://www.w3.org/2001/XMLSchema-instance"&chr(34)&" xmlns:xsd="&chr(34)&"http://www.w3.org/2001/XMLSchema"&chr(34)&" xmlns:soap="&chr(34)&"https://schemas.xmlsoap.org/soap/envelope/"&chr(34)&">"
Body = Body & "<soap:Body>"
Body = Body & "<Hello xmlns="&chr(34)&"http://tempuri.org/"&chr(34)&" />"
Body = Body & "</soap:Body>"
Body = Body & "</soap:Envelope>"

oRequest.Body = Body
Set oResponse = oConnection.Send(oRequest)

Sample: Simple Web Service

The following simple Web service code returns a "Hello World" string when the "Hello" Web method is called. You can use this sample to check that your ACT test script functions correctly.

SampleWS.asmx

<%@ webservice language=c# class=SampleWS.HelloWorld %>
using System.Web.Services;

namespace SampleWS
{
  public class HelloWorld
  {
    [WebMethod]
    public string Hello()
    {
    return "Hello World";
    }
  }
}

.NET Framework Version 1.1 Considerations

.NET Web services support HTTP GET, HTTP POST, and SOAP protocols. By default, in .NET Framework 1.1, HTTP GET and HTTP POST are both disabled.

Enabling HTTP GET and HTTP POST

You can enable the HTTP GET and HTTP POST protocols either for a specific Web service using Web.config or for the entire computer using Machine.config.

Web Config

Use the following configuration in a specific Web.config file in the virtual root directory where the Web service resides. The following configuration enables both HTTP GET and HTTP POST.

<configuration>
    <system.web>
    <webServices>
        <protocols>
            <add name="HttpGet"/>
            <add name="HttpPost"/>
        </protocols>
    </webServices>
    </system.web>
</configuration>

Machine.config

The following example enables HTTP GET, HTTP POST, and SOAP; it also enables HTTP POST for requests from localhost.

<protocols>
  <add name="HttpSoap"/>
  <add name="HttpPost"/>
  <add name="HttpGet"/> 
  <add name="HttpPostLocalhost"/>
</protocols>

More Information

For more information about enabling these protocols, see Knowledge Base article 819267, "INFO: HTTP GET and HTTP POST Are Disabled by Default" at https://support.microsoft.com/default.aspx?scid=kb;en-us;819267.

Additional Resources

For more information, see the following resources:

patterns & practices Developer Center

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

© Microsoft Corporation. All rights reserved.