Record a SOAP request

This section illustrates another means of defining SOAP request. Of all the techniques described so far, it is the one that resembles the most what you usually do with HTTP requests: acting as a user and letting NeoLoad do the job of recording requests and responses. The example uses the Google search API. For more information about this API you will need to create an account and obtain a license key, see http://www.google.com/apis

  1. The example is basic and really simple so that the underlying mechanisms are made clear:

    The HTML page you will be recording consists of a Test button and a textarea containing the request to send. Hitting the Test button sends the request to the correct end point, the response is then displayed in the textarea. The request contains an invocation to the Google search API. The body of the request contains among others, an XML key element which you will have to obtain from Google. The XML q element is the text you are actually searching for. In your very basic interface you can change this by editing the textarea content before invoking the request.

    The JavaScript code that manages the request opens the service end point, consistently sets the HTTP headers and sends the content of the textarea. When the response is received it is content is copied to the textarea. Note the code only works with Microsoft Internet Explorer. Other browsers will in any case refuse to connect to a URL not belonging to the same domain as the test page.

    The following listing contains the SOAPTest.html code and the code of the function called when the Test button is hit:

    <html>
     <body>
    
    
    <h1>Google</h1>
      
      <script type="text/javascript">
       function doIEGoogle() {
        
          textarea = document.getElementById("debugbox");
          xhr = new ActiveXObject("Microsoft.XMLHTTP");
          xhr.open('POST', "http://api.google.com/search/beta2");
          xhr.setRequestHeader("SOAPAction", "urn:GoogleSearchAction");
          xhr.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
          xhr.onreadystatechange = 
             function() {
                if(xhr.readyState != 4) return;
                if(xhr.status != 200) {
                   textarea.value = xhr.status + " " + xhr.statusText 
                      + "\n" + xhr.responseText;
                   return;
                }
                textarea.value = xhr.responseText;
             };
          xhr.send(textarea.value);
       }   
       
      </script>
      
      <form name="input" action="javascript:doIEGoogle()">
       <input type="submit" value="Test">
      </form>
      <p></p>
      
      <textarea rows="30" cols="100" name="debugbox">
    <?xml version='1.0' encoding='UTF-8'?>
    <SOAPENV:Envelope 
     xmlns:SOAPENV="http://schemas.xmlsoap.org/soap/envelope/" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <SOAPENV:Body>
    
    
    <ns1:doGoogleSearch
     xmlns:ns1="urn:GoogleSearch"
     SOAPENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
     
     <key xsi:type="xsd:string">ABQIAAAA-YwsmHQspwIU9OcKL4b5rhTd9gLE95ZWCg
    lQjFVS1XYlL9GwFBSIRS2y1JQBK8NE1ktm1oJWkWiTZQ</key>
     <q xsi:type="xsd:string">load testing web applications</q>
     <start xsi:type="xsd:int">0</start>
     <maxResults xsi:type="xsd:int">3</maxResults>
     <filter xsi:type="xsd:boolean">false</filter>
     <restrict xsi:type="xsd:string"/>
     <safeSearch xsi:type="xsd:boolean">false</safeSearch>
     <lr  xsi:type="xsd:string"/>
     <ie  xsi:type="xsd:string"/>
     <oe xsi:type="xsd:string"/>
    </ns1:doGoogleSearch>
    
    
    </SOAPENV:Body>
    </SOAPENV:Envelope>
    
    
       </textarea>
        
     </body>
    </html>
  2. Record the page:
  3. Edit the SOAP request: If you select the Edit XML Content button and choose the XML Tree Tab, you can easily browse through the SOAP request elements. This is typically where you could use variables, changing for instance the search text for the q parameter:
  4. Check the SOAP request: As for any SOAP request, you can test the recorded request by selecting the Check button to open the Check Virtual User dialog box. In this simple example, the Java script code just fills in the textarea with the received XML. In a real world scenario, the HTML page would obviously do otherwise, it would probably analyze the results, display them neatly in HTML and then let the user navigate on those results. Keep in mind that NeoLoad, just as for HTML requests, will let you extract information from the SOAP response and inject that information in further requests.
  5. Record from a real client: The previous sample shows how to record the request using a web browser. For more information, see Record a SOAP request.