Home > LoadRunner > Web Services performance using LoadRunner HTTP Vuser script

Web Services performance using LoadRunner HTTP Vuser script

January 24th, 2009

Small (basic) example howto test performance of Web Service using LoadRunner API.

Let say we have a web services that uses SOAP over HTTP. We want to check how fast we can send a request and receive a response.  Because our service uses HTTP as a transport protocol, we are able to test it using simple HTTP Vuser script.

Here is the C code:

  1. Action()
  2. {
  3.    web_reg_save_param("Response","LB=", "RB=", LAST);
  4.    web_add_header("SOAPAction", "SampleMethod");
  5.    lr_start_transaction("REQ");
  6.    web_custom_request("Sample_Request","Method=POST",
  7.          "Mode=HTML",
  8.          "RecContentType=text/xml",
  9.          "EncType=text/xml; charset=utf-8",
  10.          "URL=http://example.com:1234/sample/",
  11.          "Body=<Envelope xmlns=\"http://example.com/sample\">\n"
  12.                "   <Header/>\n"
  13.                "   <Body>\n"
  14.                "      <price><id>001</id></price>\n"
  15.                "   </Body>\n"
  16.                "</Envelope>",
  17.    "LAST");
  18.    lr_end_transaction("REQ", LR_AUTO);
  19.    lr_output_message("Response is : %s\n", lr_eval_string("{Response}"));
  20.    return 0;
  21. }

Have a fun…

  1. February 23rd, 2009 at 10:23 | #1

    Many people do not realise that they don’t really need a Web Services vuser to test web services, and they can make do by using a standard Web (HTTP/HTML) virtual user.

    I wrote a very similar post called Testing Web Services With a Standard Web Vuser.

    Cheers,
    Stuart.

  2. admin
    February 23rd, 2009 at 22:03 | #2

    Yes, thats true. We have to make these people aware :)

    Waldemar

  3. Tauhid Khan
    March 4th, 2009 at 18:28 | #3

    How do you handle authentication if the URL needs user id and password?

  4. Waldemar
    March 4th, 2009 at 19:20 | #4

    Tauhid,

    You can setup proxy by using web_set_user() function from LR API.

    web_set_user(”domain\\michael”, “abc”, “proxy.example.com:80″);

    Waldemar

  5. Lucky
    June 25th, 2009 at 15:56 | #5

    Hi Waldemar,

    Thats really a nice idea I am new to web services protocol, I have created script with SOAP request sucessfully.
    As we require Web services license to execute this SOAP request script. I thought of doing it with HTTP/HTML Protocol if possible.
    I have tried the way is is given above.
    Facing some issues with it can someone help me in this. I am not clear what is “Sample_Request” & “SampleMethod” here in above post.
    The URL which we are giving doest open manually in my case that is why I am getting 400 Bad request error. What can I do to resove this solution?

    Any sugesstion will be great help for me?

    Thanks
    Lucky

  6. Waldemar
    June 25th, 2009 at 18:46 | #6

    Have you tried asking your developers? Maybe they can help.

    “Sample_Request” is just a step name. You can put here anything.
    “SampleMethod” is a method name that you want to call on web service. You should find it in your WSDL file.

    Waldemar

  7. Lucky
    July 16th, 2009 at 10:59 | #7

    Hi Waldemar,

    Thanks for your valuable reply.

    I have got the informations but in my case the problem is the URL which they have provided not opening up directly through web browser it show 400 error so I am not able to make it sucessful. But I liked this post.
    May I have some sample WSDL file so I can practice on it and make myself more comfortable with converting web services into http request.
    That will be greate help for me if you can provide me smaple WSDL with all required information as I mentioned in my previous post.

    Thanks,
    Lucky

  8. Waldemar
    July 21st, 2009 at 20:57 | #8

    Sure,

    You can try with web service provided by Parasoft for SOATest tutorial.
    Here is the WSDL URL: http://soatest.parasoft.com/store-01.wsdl
    And two sample requests:

    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    3.  <SOAP-ENV:Body>
    4.   <getItemByTitle xmlns="http://www.parasoft.com/wsdl/store-01/">
    5.    <titleKeyword>Linux</titleKeyword>
    6.   </getItemByTitle>
    7.  </SOAP-ENV:Body>
    8. </SOAP-ENV:Envelope>

    and

    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <SOAP-ENV:Envelope
    3.  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
    4.  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    5.    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    6.  <SOAP-ENV:Body>
    7.   <getItemById xmlns="http://www.parasoft.com/wsdl/store-01/">
    8.    <id>1</id>
    9.   </getItemById>
    10.  </SOAP-ENV:Body>
    11. </SOAP-ENV:Envelope>
  9. Lucky
    July 27th, 2009 at 12:34 | #9

    Hi Waldemar,

    Thank you very much. I appreciate for you response.

    I tried writing script for the same. But no luck for me I am sure I am making some mistake in it. It will greate if you guide me in this. Please have a look on below script.

    Action
    {
    web_add_header(”Content-Type”, “text/xml”);

    web_add_header(”SOAPAction”, “\”getItemByTitle\”");

    web_add_header(”User-Agent”, “XML Spy”);

    web_custom_request(”StepName=getItemByTitle”,
    “Method=POST”,
    “Mode=HTML”,
    “RecContentType=text/xml”,
    “EncType=text/xml; charset=utf-8″,
    “URL=http://ws1.parasoft.com/glue/store-01″,
    “Body= Envelope ”
    “xmlns=\”http://schemas.xmlsoap.org/soap/envelope”
    “xmlns=\”http://schemas.xmlsoap.org/soap/encoding”
    “xmlns:xsi=\”http://www.w3.org/2001/XMLSchema-instance”
    “xmlns:xsd=\”http://www.w3.org/2001/XMLSchema”
    “”
    “”
    “xmlns=\”http://www.parasoft.com/wsdl/store-01/>”
    “linux”
    “”
    “”
    “”,
    LAST);

    Thanks,
    Lucky

  10. Lucky
    July 27th, 2009 at 12:42 | #10

    Hi Waldemar,

    I apologies some part has got missed out in my earlier post. Please refer this one on behalf of earlier one.

    Action( )
    {
    web_add_header(”Content-Type”, “text/xml”);

    web_add_header(”SOAPAction”, “\”getItemByTitle\”");

    web_add_header(”User-Agent”, “XML Spy”);

    web_custom_request(”StepName=getItemByTitle”,
    “Method=POST”,
    “Mode=HTML”,
    “RecContentType=text/xml”,
    “EncType=text/xml; charset=utf-8″,
    “URL=http://ws1.parasoft.com/glue/store-01″,
    “Body= Envelope”
    “xmlns=\”http://schemas.xmlsoap.org/soap/envelope”
    “xmlns=\”http://schemas.xmlsoap.org/soap/encoding”
    “xmlns:xsi=\”http://www.w3.org/2001/XMLSchema-instance”
    “xmlns:xsd=\”http://www.w3.org/2001/XMLSchema”
    “”
    “”
    “xmlns=\”http://www.parasoft.com/wsdl/store-01/>”
    “linux”
    “”
    “”
    “”,
    LAST);
    return 0;
    }

  11. Waldemar
    July 27th, 2009 at 13:09 | #11

    Try this:

    1. Action()
    2. {
    3.    web_reg_save_param("Response","LB=", "RB=", LAST);
    4.    web_add_header("SOAPAction", "getItemByTitle");
    5.    lr_start_transaction("REQ");
    6.    web_custom_request("Sample_Request",
    7.                  "Method=POST",
    8.          "Mode=HTML",
    9.          "RecContentType=text/xml",
    10.          "EncType=text/xml; charset=utf-8",
    11.          "URL=http://ws1.parasoft.com/glue/store-01",
    12.                  "Body=<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
    13.              "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"
    14.              "<SOAP-ENV:Body>"
    15.              "<getItemByTitle xmlns=\"http://www.parasoft.com/wsdl/store-01/\">"
    16.              "<titleKeyword>Linux</titleKeyword>"
    17.              "</getItemByTitle>"
    18.          "</SOAP-ENV:Body>"
    19.          "</SOAP-ENV:Envelope>",
    20.    "LAST");
    21.    lr_end_transaction("REQ", LR_AUTO);
    22.    lr_output_message("Response is : %s\n", lr_eval_string("{Response}"));
    23.    return 0;
    24. }

    It works for me. If it doesn’t work for you, then you must have proxy settings missing in LoadRunner.

  12. Lucky
    July 28th, 2009 at 11:12 | #12

    Hi Waldemar,

    Thank you very much for you support. I appereciate your response. It works fine its amazing. It has really enhanced my knowledege on web services scripting.

    Thanks
    Lucky

  13. Waldemar
    July 28th, 2009 at 11:13 | #13

    No problem :)

  14. Manny
    July 29th, 2009 at 21:44 | #14

    Guys . Im very new at LR , Im using version 9.5. I also have SOA and would like to lear how to test them via regular Web User.
    My SOA accept several parameters, so Im listing them in sequence.. I must be doing something very wrong,, when I run the script on Vugen I get :
    Action.c(6): HTTP/1.1 500 Internal Server Error\r\n
    Action.c(6): Server: Sun-Java-System-Web-Server/7.0\r\n
    Action.c(6): Date: Wed, 29 Jul 2009 20:36:14 GMT\r\n
    Action.c(6): X-powered-by: Servlet/2.5\r\n
    Action.c(6): Content-type: text/xml;charset=”utf-8″\r\n
    Action.c(6): Date: Wed, 29 Jul 2009 20:36:11 GMT\r\n
    Action.c(6): Transfer-encoding: chunked\r\n
    Action.c(6): \r\n
    Action.c(6): t=921ms: 5-byte chunked response overhead for “https://192.168.1.203:443/webservice/MyServices” (RelFrameId=1, Internal ID=1)
    Action.c(6): 1a0\r\n
    Action.c(6): t=929ms: 7-byte chunked response overhead for “https://192.168.1.203:443/webservice/MyServices” (RelFrameId=1, Internal ID=1)
    Action.c(6): \r\n
    Action.c(6): 0\r\n
    Action.c(6): \r\n
    Action.c(6): t=958ms: 416-byte chunked response body for “https://192.168.1.203:443/webservice/MyServices” (RelFrameId=1, Internal ID=1)
    Action.c(6): ns2:ClientCannot find d
    Action.c(6): ispatch method for {https://192.168.1.203:443/webservice/MyServices/}get
    Action.c(6): X
    Action.c(6): Error -26612: HTTP Status-Code=500 (Internal Server Error) for “https://192.168.1.203:443/webservice/MyServices” [MsgId: MERR-26612]
    Action.c(6): Notify: Saving Parameter “Response = HTTP/1.1 500 Internal Server Error\r\nServer: Sun-Java-System-Web-Server/7.0\r\nDate: Wed, 29 Jul 2009 20:36:14 GMT\r\nX-powered-by: Servlet/2.5\r\nContent-type: text/xml;charset=”utf-8″\r\nDate: Wed, 29 Jul 2009 20:36:11 GMT\r\nTransfer-encoding: chunked\r\n\r\nns2:ClientCannot find dispatch method for {https://192.168.1.203:443/webservice/MyServices/}getX”
    Action.c(6): t=984ms: Closing connection to 192.168.1.203 after receiving status code 500 [MsgId: MMSG-26000]
    Action.c(6): t=992ms: Closed connection to 192.168.1.203:443 after completing 0 requests [MsgId: MMSG-26000]
    Action.c(6): t=996ms: Request done “https://192.168.1.203:443/webservice/MyServices” [MsgId: MMSG-26000]
    Action.c(6): web_custom_request(”Sample_Request”) highest severity level was “ERROR”, 416 body bytes, 247 header bytes, 12 chunking overhead bytes [MsgId: MMSG-26387]

    I think Im writing the Body wrongly.
    Anybody seen this before?
    Thanks!!

  15. Waldemar
    July 30th, 2009 at 06:49 | #15

    { and } characters in URL looks like something incorrect.

    {https://192.168.1.203:443/webservice/MyServices/}getX

    probably should be

    https://192.168.1.203:443/webservice/MyServices/getX

  16. Manny
    July 30th, 2009 at 17:16 | #16

    That was the answer from the server. My script doesnt have the { } .
    Basically what I did was using your script and make some changes according to my WSDL. Like this:

    Action()
    {
    web_reg_save_param(”Response”,”LB=”, “RB=”, LAST);
    web_add_header(”SOAPAction”, “getX_101″);
    lr_start_transaction(”REQ”);
    web_custom_request(”Sample_Request”,
    “Method=POST”,
    “Mode=HTML”,
    “RecContentType=text/xml”,
    “EncType=text/xml; charset=utf-8″,
    “URL=https://192.168.1.203:443/webservice/Services”,
    “Body=”
    “”
    “”
    “”
    “user1@gmail.com”
    “developer”
    “20T70″
    “1234567896″
    “TLS”
    “STANDARD”
    “syn”
    “1″
    “”
    “”
    “”
    “”
    “”
    “”,
    “LAST”);
    lr_end_transaction(”REQ”, LR_AUTO);
    lr_output_message(”Response is : %s\n”, lr_eval_string(”{Response}”));

    return 0;

    }

    Im sure Im doing something wrong on the script,, but I dont know where, since this is the first time I try it.
    Thanks!!!

  17. Manny
    July 30th, 2009 at 17:18 | #17

    How can I paste the script here? is chunking my characters.
    :-(

  18. Waldemar
    July 30th, 2009 at 17:30 | #18

    please use [ code lang="c" ] and [ / code ] to post source code

  19. Waldemar
    July 30th, 2009 at 18:06 | #19

    Sorry, I should warn you. Don’t use spaces. I could not put code tag literally because it will be interpreted.

  20. Manny
    July 30th, 2009 at 18:06 | #20

    Obviously I dont know how to use this. :-) ,, Hopefully you can delete all my erroneous junk from your Blog.
    Apologies.

  21. Manny
    July 30th, 2009 at 18:07 | #21
    1. Action()
    2.         {
    3.            web_reg_save_param("Response","LB=", "RB=", LAST);
    4.            web_add_header("SOAPAction", "getX_101");
    5.            lr_start_transaction("REQ");
    6.            web_custom_request("Sample_Request",
    7.                          "Method=POST",
    8.                          "Mode=HTML",
    9.                          "RecContentType=text/xml",
    10.                          "EncType=text/xml; charset=utf-8",
    11.                          "URL=https://192.168.1.203:443/webservice/Services",
    12.                                   "Body="
    13.                                  ""
    14.                                  ""
    15.                                  ""
    16.                                  "user1@gmail.com"
    17.                                  "developer"
    18.                                  "20T70"
    19.                                  "1234567896"
    20.                                  "TLS"
    21.                                  "STANDARD"
    22.                                  "syn"
    23.                                  "1"
    24.                                  ""
    25.                                  ""
    26.                                  ""
    27.                                  ""
    28.                          ""
    29.                          "",
    30.            "LAST");
    31.            lr_end_transaction("REQ", LR_AUTO);
    32.            lr_output_message("Response is : %s\n", lr_eval_string("{Response}"));
    33.        
    34.        
    35.        
    36.                 return 0;
    37.        
    38.         }
  22. Waldemar
    July 30th, 2009 at 18:11 | #22

    in my understanding it should work, drop me an email instead

  23. Manny
    July 30th, 2009 at 19:15 | #23

    I sent you the email to the address on this blog,, thanks!!

  24. Sakar2009
    August 3rd, 2009 at 15:00 | #24

    Hi Waldermar,

    It is a nice blog thank you for that, I tried your sample web service script you pasted above (Parasoft Tutorial) and it worked fine . However I have one question that, I have created exactly similar script for the web sevice I want to Load test , I keep getting error.

    Action.c(6): Notify: Transaction “REQ” started.
    Action.c(7): Error -26612: HTTP Status-Code=500 (Internal Server Error) for “http://sac02v.itutl1.com/Data/pit/pit.asmx” [MsgId: MERR-26612]
    Action.c(7): web_custom_request(”Sample_Request”) highest severity level was “ERROR”, 418 body bytes, 238 header bytes [MsgId: MMSG-26388]
    Action.c(7): Notify: Transaction “REQ” ended with “Fail” status (Duration: 3.9200 Wasted Time: 0.0000).
    Ending action Action.

    Pls help me to Debug this issue.

    Thanks & Regards,

  25. Waldemar
    August 3rd, 2009 at 15:14 | #25

    500 internal server error in most cases means your input values are incorrect. Double check each value, XML tags, etc. Sometimes one space can break whole request.

    Waldemar

  26. Ary
    August 14th, 2009 at 06:56 | #26

    Hi Waldemar,

    New joinee to your site. As you mentioned, we can test web services using HTTP protocol. My application is using both HTTP and web service and a lot of soap request and responses are there in every navigation and data fetch operations.
    I tried with HTTP, those step are not at all getting recorded but they are getting recorded with multiprotocol HTTP/web services.
    Since we dont have license for web services, I just want to know that if it is really possible to do web services load test using only HTTP protocol with help the coding for large applications also.

  27. Sakar2009
    August 17th, 2009 at 16:29 | #27

    Hi Waldemar,

    First of all thank you for the reply. I have double checked all the spaces and have re-done it still get 500 server error. Is there any firewall or security concerns blocking by request xml?. I am now also involved in a load testing URL with .svc extension ( WCF WebService) instead of .asmx Can we load test this service using only HTTP/HTML protocol?

  28. Waldemar
    August 17th, 2009 at 20:30 | #28

    Ary:
    Yes, it is possible to test web services with HTTP only. But to be honest HTTP and Web Services are two different thinks. HTTP is a transport protocol but Web Service is a software designed in a special way. Web Services communicate using SOAP messages (more details here http://www.w3.org/TR/soap/). But SOAP specification doesn’t define transport protocol. That’s why the easiest way is to use HTTP protocol to send/receive SOAP messages over the network. And most web services use HTTP but there are some that use other transport protocols (JMS for example). So as long as your web service use HTTP to communicate over the network, you should be able to test it using any HTTP client (including LoadRunner HTTP/HTML script).

    Sakar2009:
    Check if you use any proxy in IE. You can set it in Vuser -> Run-Time settings.

  29. Sakar2009
    August 18th, 2009 at 12:16 | #29

    Hi Waldemar,
    I have selected obtain proxy settings from default browser under Vuser->RunTime Settings. still get the same Internal Server Rrror – 500.

  30. sunny2009
    August 18th, 2009 at 16:24 | #30

    Hi Waldemar,
    Trying to test a WCF webservice with .svc extention using above method of using HTTP Protocol. I am getting HTTP Status-Code=400 message. Pls help me to debug this issue:

    Error -26631: HTTP Status-Code=400 (Bad Request) for “http://114.13.9.4/CoBuSHost_FW/FService.svc” [MsgId: MERR-26631]
    Action.c(13): Error -26377: No match found for the requested parameter “sessionID”. Check whether the requested boundaries exist in the response data. Also, if the data you want to save exceeds 256 bytes, use web_set_max_html_param_len to increase the parameter size [MsgId: MERR-26377]
    Action.c(13): Error -26374: The above “not found” error(s) may be explained by header and body byte counts being 187 and 0, respectively. [MsgId: MERR-26374]
    Action.c(13): web_custom_request(”CoService”) highest severity level was “ERROR”, 0 body bytes, 187 header bytes [MsgId: MMSG-26388]
    Ending action Action.

  31. Waldemar
    August 18th, 2009 at 17:06 | #31

    sunny2009
    Hmmm, probably HTTP header or message body is incorrect. Do you use IIS server to handle web services?

  32. sunny2009
    August 20th, 2009 at 12:43 | #32

    Yes we use IIS server to handle web services, double checked the message body and the string which goes as input XML, not able to get a response from the server.

  33. Ary
    August 21st, 2009 at 15:17 | #33

    Hi Waldemar,

    I appreciate your response. Thanks.
    I tried but not able to record the script using web protocol. But it is recording using web/web service dual protocol and working very well. Please let me know if there is any workaround for doing it using only web protocol. And my UI is silverlight and handling web services using IIS web server.
    Using web services protocol, I am able to capture all the requests but I want the reponse time for all the soap request/web service call individually. I mean to say I want the break up of the response time of a transaction in terms of every request. web page diagnostic is not working for web service protocol, I checked. Is there any way for diagnostic?

  34. Jigar
    September 16th, 2009 at 04:57 | #34

    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.

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

    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

  35. Waldemar
    September 16th, 2009 at 16:38 | #35

    Hi Jigar
    It can be anything. It’s hard to say. For me it looks ok. But if you have another client that is able to connect there correctly I would start from sniffing the traffic using wireshark.

  1. No trackbacks yet.