Testing Web Services With a Standard Web Vuser
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> <SPEECH> <PLAY>TWELFTH NIGHT</PLAY> <SPEAKER>MALVOLIO</SPEAKER> 'Be not afraid of greatness:' 'twas well writ.</SPEECH> </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; } |
Related posts:
- Monitoring Tomcat with LoadRunner LoadRunner does not come with a monitor for Tomcat. Fortunately,...
- Load balancing vusers without a load balancer Recently I ran a test at a company which had...
- The “is it done yet” loop Occasionally you will find that you must write some code...
- What’s New in LoadRunner 9.50? LoadRunner 9.5 was released today and, as mentioned by the...
- Changing LoadRunner/VuGen log options at runtime LoadRunner has a whole bunch of logging options. These can...
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
February 23rd, 2009 at 4:06 pm
Waldemar Sojka has written something simlar for his blog: Web Services performance using LoadRunner HTTP Vuser script
March 5th, 2009 at 3:27 am
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"). ]
September 16th, 2009 at 1:57 pm
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)
Would you please be able to help.
Regards,
Jigar
September 16th, 2009 at 9:18 pm
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.
September 29th, 2009 at 5:05 am
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.
September 29th, 2009 at 10:07 am
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.
April 14th, 2010 at 10:00 pm
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