It is possible to test web services using the standard Web (HTTP/HTML) virtual user type instead of the Web Services vuser type. The main disadvantage of this is that you cannot generate your SOAP body from the WSDL file using the VuGen wizard. But if you know what your XML request should look like, then you shouldn’t have any real problems.

Here are my tips:

  • Send your SOAP payload using lr_custom_request().
  • Add a SOAPAction HTTP header using web_add_header().
  • Remove unnecessary HTTP headers (that are generated automatically by VuGen) with web_remove_auto_header().
  • Don’t forget to verify that you get a valid response. Use web_reg_find() for a simple check. For better verification of the SOAP response use lr_xml_find().
  • To extract values from the response body, use lr_xml_get_values(). Brush up on your XPath qeries beforehand though.
  • It may be necessary to HTML-encode some characters in your XML/SOAP message (e.g. convert “&” to “&”). Unfortunately VuGen does not provide this functionality (but HP could easily add it to the web_convert_param function), so you will have to either write (or find) a function to do it, or convert all the entries in your data table before running the script.

As an example, here is a simple script that makes use of a web service that will look up the source of a Shakespeare quote for you. The WSDL is available from http://www.xmlme.com/WSShakespeare.asmx?wsdl.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
Action()
{
  // ContentCheck Rules for known error messages
  web_global_verification("Text=Speech not found", "ID=SpeechNotFound", LAST);
 
  lr_start_transaction ("Search For Shakespeare Quote");
 
  // By default, VuGen sends a user-agent header.
  // Let's remove this as an example of removing automatically generated headers.
  web_remove_auto_header("User-Agent", "ImplicitGen=No", LAST); 
 
  // Add a SOAPAction HTTP header
  web_add_header("SOAPAction", "http://xmlme.com/WebServices/GetSpeech");
 
  // Save entire body from the HTTP response for later checking with lr_xml_find.
  web_reg_save_param("ResponseBody",
    "LB=",
    "RB=",
    "Search=Body",
    "IgnoreRedirections=Yes",
    LAST);
 
  // Note that the text to search for would normally be replaced with a parameter,
  // and so would the <Request> element of the below SOAP message.
  web_reg_find("Text=TWELFTH NIGHT", LAST);
 
  web_custom_request("Search Shakespeare", 
    "URL=http://www.xmlme.com/WSShakespeare.asmx", 
    "Method=POST", 
    "Resource=0", 
    "Referer=", 
    "Snapshot=t1.inf", 
    "Mode=URL", 
    "EncType=text/xml; charset=utf-8", 
    "Body=" // As it is SOAP, you are unlikely to have to use BodyBinary, unless your request has CDATA.
    "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
    "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:wsa=\"http://schemas.xmlsoap.org/ws/2004/03/addressing\" xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\" xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">"
    "<soap:Body>"
    "<GetSpeech xmlns=\"http://xmlme.com/WebServices\">"
    "<Request>Be not afraid of greatness</Request>"
    "</GetSpeech>"
    "</soap:Body>"
    "</soap:Envelope>",
    LAST);
 
  // The response from the web service looks like this:
  /*
  <?xml version="1.0" encoding="utf-8"?>
  <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
      <GetSpeechResponse xmlns="http://xmlme.com/WebServices">
        <GetSpeechResult>
          &lt;SPEECH&gt;
          &lt;PLAY&gt;TWELFTH NIGHT&lt;/PLAY&gt;
          &lt;SPEAKER&gt;MALVOLIO&lt;/SPEAKER&gt;
          'Be not afraid of greatness:' 'twas well writ.&lt;/SPEECH&gt;
        </GetSpeechResult>
      </GetSpeechResponse>
    </soap:Body>
  </soap:Envelope>
  */
 
  // An example of extracting the a value from a SOAP reponse.
  // This saves the <GetSpeechResult> element into {OutputParameter}.
  // The same syntax could be used with lr_xml_find to check the response.
  lr_xml_extract("XML={ResponseBody}", 
    "XMLFragmentParam=OutputParameter", 
    "Query=/soap:Envelope/soap:Body/GetSpeechResponse/GetSpeechResult", LAST);
  lr_output_message("Source of Shakespeare quote: %s", lr_eval_string("{OutputParameter}"));
 
  lr_end_transaction ("Search For Shakespeare Quote", LR_AUTO);
 
  return 0;
}

23 comments on “Testing Web Services With a Standard Web Vuser

  1. Hi, I am having trouble with the xml extract and xml find. I tried similar format with my response and the function is not able to find or extract. I ran the same example above and see that the lr_xml_extract is failing. Can you help, please?

    1. Hi Deepa,

      I copied the code into a new script and it appears to be working now – have another go.

      Getting the XPath can be tricky, but there are a few different websites that can help. Online validators let you paste in your XML and check your XPath expressions return results. Try googling ‘online xpath validator’ and pick one that suits.

  2. Hi there,

    I am using LR 11.52 and trying to pass a soap request using web_custom_request.

    When script is replayed, it is throwing Internal 500 error. I have checked the request in the LR output log and it seem to be correct.

    Also, the same request is displaying correct response when run in SOAP UI.

    Could you tell me possible causes/ solution?

    I have attached the script too.

    Thanks

  3. Hi Stuart,

    I was going through the various topic listed here..
    Could you please help me out in the problem listed below-
    Problem -> I have a .Net WebAPI for fetching the data from the database.
    It is using JSON data to POST the requests.
    In the Request Body we pass the required parameters and in Headers we pass the “Security token” along with other parameters.
    Developer has written a logic to Generate the Unique Security token each time and add into Header, before posting the JSON body.

    I have the DLL which has the logic of generating the security token.
    The Problem is -> How can i use this DLL so that, EACH time when i run the script from VUgen, it will ADD the Security token parameter in the HEADERS and After that POST the request body.
    It is something like (in simple words) – When we run the VUgen script -> The DLL methods will add the Security Token parameter in the Headers and THEN, the Scripts execution will proceed with this security token and Post the request to server.

    Could you please let me know, if it is possible to ADD the security token in the PRE Request ?
    Note – VUgen script i have created using the Fiddler’s .SAZ file and it contains the web_custom_request() method
    let me know, if you need any more information.

    Thanks,
    Sam

  4. Hi,

    Thanks for the helpful information!

    I want to test file upload using Loadrunner for Web Services, is this feasible? It would be a great help if you can guide me with few steps.

    thanks.

  5. I need a load runner script to capture the CPU , Memory utilization.
    i have around 70 servers to be monitored , which is impossible for me to manually login and check them indivigually. Is there a way i can do it through load runner

    Can someone provide me an exact code in LR, using plink. i was able to run the command but not capture the response

  6. Hi , Can you please help me to capture the XML request not the response.

    Reason for this , Development team require to debug the xml request based on the response which we are receiving from the server for the different kind of data.

  7. How to map WS configuration in HP Load Runner for web service protocol:

    I have imported WSDL and included the certificate with the help of web_set_certificate function. but again some behind wsi configuration need to setup. Any one have any idea how to map it?

    In SOUPUI Pro -> have an option to include one configuration. Each configuration will have a Username and a Signature entry.
    These entries will be applied to the corresponding outgoing SOAPUI message in the Security Header when the message is sent.

    Go to project name “test”, right-click
    Select “Show Project View”
    Go to “WS-Security Configurations” tab
    Click the Add button

  8. I am trying to performance test a web service using web_custom_request but the web service requires server authentication and i am getting below error.

    Action.c(6): Error Exceptions:
    Action.c(6): System.Exception: Soap error:
    Message:ITW Agent cannot locate all required security information.Username is missing. Password is missing.
    at Mercury.LR.LrWsNetClient.ProxyCreator.InvokeMethod(String sMethod, IWSMethodParameters mParams, String sAsyncEvent)
    at Mercury.LR.LrWsNetClient.NetReplay.InvokeMethod(String sMethod, IWSMethodParameters mParams, String sAsyncEvent)

    Action.c(6): Error:Expected SOAP result, received SOAP fault
    Action.c(6): Error:Failed to retrieve output arguments/checkpoints – SOAP fault occurred

    I tried using web_set_user(“username”, “password”, “www.example.com:443”) function but did not work.

    Could you please help me get through this?

    Thanks in Advance

  9. I am doing performance testing of an desktop application, the communication protocol is web service so I adopt the approach to do the webservice scripting using HTTP/HTML protocol.

    Cliet application is developed in .net and server is windows 2003. I have build the Loadrunner script successfully, while executing the same I am facing below error . I am struggling a lot in order to fix this issue . Any sort of help is really appreciable .
    ===========================================================================
    Action.c(16): Continuing after Error -26630: HTTP Status-Code=401 (Unauthorized) for “https://fci-bccwqahyb02.sysdev.adroot.bmogc.net/FormsProcessingWebServicePhase2/PrefillService.svc” [MsgId: MERR-26630]
    =================================================================================

  10. Hi,

    I am trying to create a web_custom_request using XML to test web service. In web_custom_request which URL needs to used? Is it WSDL or anything else? What is the exact terminology used for this URL? I am not able to understand which url to ask from dev team to use in custom_request. Can someone please help me?

    Thanks,
    Adil

  11. Hi Team,

    Can you pls help me resolving this issue i got struck over here for past 2 days,searching for the solution

    ie i am trying to place an webservice request, as specified above. But after execution it is throwing error as

    Error -26631: HTTP Status-Code=400 (Bad Request) for

  12. hi,
    I am trying to post the xml to the web service, but i get the 500 Internal error as below.

    response headers for “http://wbv-oal-t0001/Outage_Communicator/getOutageCommunicatorServiceStatus.asmx” (RelFrameId=1, Internal ID=1)
    HTTP/1.1 500 Internal Server Error\r\n

    Can you please help me if I am missing anything in the script.

    web_add_header(“Content-Type”,”text/xml; charset=ISO-8859-1″);

    web_add_header(“SOAPAction”,”http://wbv-oal-t0001/Outage_Communicator/getOutageCommunicatorServiceStatus\””);
    web_custom_request(“getOutageCommunicatorServiceStatus”,
    “URL=http://wbv-oal-t0001/Outage_Communicator/getOutageCommunicatorServiceStatus.asmx”,
    “Method=POST”,
    “TargetFrame=”,
    “Resource=0”,
    “Referer=”,
    “Body=\r\n”
    ” \r\n”
    ” \r\n”
    ” \r\n”
    \r\n”
    ” 01\r\n”
    \r\n”
    ” 0101\r\n”
    ” \r\n”
    ” \r\n”
    “”,
    LAST);

    Thanks,
    Radan

  13. I guess, in order to post web service request via http/html protcol(use web_custom_request) a web page is required.
    The purpose of the web page is to take input parameters for the XML/SOAP request to the server.

    What are the criteria for designing a web page to host XML/SOAP requests?

    If the above approach is not correct, can you please guide me with the right information from scratch- how to use web_custom_requests i.e post web services via http/html?

    Thanks much in advance.

    1. If you are looking for a web service to practice writing a LoadRunner/VuGen script for, then you should look at the API Directory from ProgrammableWeb.

      If you are wanting to develop your own web service, then you will need a web server with a server-side scripting language like PHP or C#. Once you know what language/platform you are using, it should be easy to find a tutorial on creating web services.

      Using someone else’s web service is the easiest way to go if you just want to practice creating LoadRunner/VuGen scripts though…

      Cheers,
      Stuart.

  14. Hello,

    I have a query regarding a mixed approach taken by project. It is a mixed approach of WebMethods and HTTP Post method.

    Project is using WebMethods for integration. But it is not using SOAP or WSDL. It is just exposing method. A .NET client is using MSXML2.XMLHTTP40 object to send data (XML) using HTTP POST method.

    I have to emulate similar. I tried code to submit data using web_custom_request and web_submit_data. I can login fine using web_set_user. But i receive HTML status code – 403 when code moves to submit request.

    Following is a web_custom_request call: (do note that I have changed certain parameters)

    1
    2
    3
    4
    5
    6
    7
    
    web_custom_request("http://WebMethodServer:1000/invoke/ClassName.ClassName.receive/FunctionName", 
        "Method=POST",
        "URL=http://wmdevis:6223/invoke/GDTCostarCommon.CostarMPS.receive/mpsDataUpload",
        "Mode=HTML",
        "EncType=text/xml; charset=utf-8",
        "Body=<?xml version="1.0" encoding="UTF-8"?>DATA",
        LAST);

    Would you please be able to help.

    Regards,
    Jigar

    1. An HTTP 403 response means that authentication is probably failing. It would be a good idea to have a look in the web server log to see if there is more information about why it is failing (i.e. sc-substatus and sc-win32-status).

      I am happy to have a look at your script if you send it to me.

      Cheers,
      Stuart.

  15. Could you please let me know what I need to do when accessing the URL needs authentication. What will need to be changed in the “web_custom_request” code block.

    [Stuart’s Reply: To handle a web service that requires authentication, you need to put a call to the web_set_user() function at the top of your script.

    This function supports Basic authentication, Digest access authentication, NTLM, NTLMv2, and Kerberos (with some extra mucking around).

    Note that if the username you are authenticating with is on a domain, you may have to include the domain in the username field. e.g. web_set_user(“domain\\username”, “password”, “www.example.com:443”). ]

Leave a Reply