Sunday, 18 January 2015

Web Services - SOAP scripting in LoadRunner

           
Web Services - SOAP scripting

In this blog, we are going to see how web services works and what are the ways to do to a SOAP scripting in LoadRunner.

So what is a WebService?
Web services are self-contained applications that can run universally across the Internet. They are built using Extensible Markup Language (XML) and Simple Object Access Protocol (SOAP). They serve as building blocks enabling the rapid development and deployment of new applications. They are primarily used as a means for businesses to communicate with each other and with clients; Web services allow organizations to communicate data without having intimate knowledge of each other's IT systems behind the firewall.

Unlike traditional client/server models, such as a Web server/Web page system, Web services do not provide the user with a user interface. Instead, Web services share business logic, data and processes through a programmatic interface across a network. Developers can then add the Web service to a user interface (such as a Web page or an executable program) to offer specific functionality to users.

Web services allow different applications from different sources to communicate with each other without time-consuming custom coding. In addition, because all communication is in XML, Web services are not tied to any one operating system or programming language.

 How LoadRunner(LR) works for SOAP request?
Using LR, we can directly send the SOAP requests to the Web services by bypassing the UI and the JSP pages.
1.      LR sends a SOAP request the Web service
2.      Web service process the requests and the SOAP response back.


Scripting
Typically a Web service does not have a user interface that can be used for scripting. So in that case, we need to depend on the development team to get the SOAP data that the web service takes as input and their corresponding success and failure codes.
We have 3 ways that LR can be used for scripting:
  1. Using soap_request
  2. Using a WSDL wizard.
  3. Using web_custom_request.  

1.  Using soap_request
1.      Open VuGen and create a Web Services script.
2.      Create a soap_request call in the Action.

soap_request("StepName=",
"URL= ",
"SOAPEnvelope= ",
"Snapshot= ",
"ResponseParam= ",
LAST);

StepName                   - Text describing the Web Services step (Any free text).
URL                              - URL of the Web service
SOAPEnvelope         - This field has the XML string that is accepted by the web service. The   AD team should provide the exact XML string that Web service takes as input.
Snapshot                     - Name of the .inf file that stores the snapshot of the step.
ResponseParam      - This field stores the response that comes back from the server. This string will be used for validating the response

3.      web_create_html_param or web_reg_save_param cannot be used here for correlation or for text checks as these functions are specific to Web(HTML/HTTP) protocol and will not work with web services. We need to define a string in the soap_request() function's ResponseParam field to capture the response from the web service and use strcmp() or strstr() to check for the success or failure codes.
4.      If required, parameterization can also be done in a similar way as we used to do in Web scripts.

2. Using a WSDL wizard.
Alternately we can use the Import WSDL (Web Services Description Language) wizard to generate the SOAP script. We haven't tried this option yet.

3. Using web_custom_request.

If the web service supports SOAP over HTTP protocol then we can also use the web_custom_request function to generate the SOAP request.

Here are the steps to create the web_custom_request
1.      Open VuGen and create a Web (HTTP/HTML) script.
2.      Select Tree View (View -> Tree view)
3.      Right click Action() and select 'Insert after' option
4.      Select 'Custom Request' in the Add Step window and click ok.
5.      Custom Request Properties windows pops up.
6.      In the Custom Request Properties window change
Method                   - POST
URL                              - Paste the URL of the web service.
Body                            - Paste the XML string that is accepted by the web service. The AD team should provide the exact XML string that Web service takes as input. Select the entire string, right click and click on 'Convert to C format' option.
Encoding Type              - Enable this check box and paste the string text/xml.
Click ok and change the view to Script view.
7.      Insert the required functions to validate the response from the server.
Note - All LR web functions can be used in this script.

 Sample example of SOAP script using soap_reques
              lr_start_transaction("TestScript");

              soap_request("StepName=A",
              "URL=http://xyz.com/servlet/arouter",
              "SOAPEnvelope= "
              "<SOAP:Envelope xmlns:SOAP=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xyze=\"http://schemas.xmlsoap.org/ws/2003/06/secext\">"
              "<SOAP:Header>"
    "<xyze:Security>"
    "<xyze:UsernameToken>"
              "<xyze:Username>essewsid</xyze:Username>"
              "<xyze:Password>9abc4</xyze:Password>"
              "</xyze:UsernameToken>"
    "</xyze:Security>"
              "</SOAP:Header>"
              "<SOAP:Body>"
              "<m:getUser xmlns:m=\"http:// xyz.com/roleService\">"
              "<profileUserID>{UID}</profileUserID>"
              "<userType>A</userType>"
              "</m:getUserRoles>"
              "</SOAP:Body>"
              "</SOAP:Envelope>",
              "Snapshot=t1.inf",
              "ResponseParam=result",
              LAST);

              rc  = strstr(lr_eval_string("{result}"),lr_eval_string("{UID}"));
             
              if (rc == NULL)
              {
                         lr_end_transaction("TestScript ", LR_FAIL);
                         lr_output_message("%s", lr_eval_string("UID {UID} TestScript not found Itrn {ItNum}, Host {LR_Host}, Vuser {VuserID}, Group {LR_Group}, Time {Time} \nresult {result}"));
                         return 0;
              }

              rc  = strstr("fault",lr_eval_string("{result}"));

              if (rc != NULL)
              {
                         lr_end_transaction("TestScript ", LR_FAIL);
                         lr_output_message("%s", lr_eval_string("UID {UID} TestScript failed Itrn {ItNum}, Host {LR_Host}, Vuser {VuserID}, Group {LR_Group}, Time {Time} return {result}"));
                         return 0;
              }

              lr_end_transaction("TestScript ", LR_PASS);

6 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. I think there is a dire need of learning and implementing as many SQL strategies and notable aspects of Soap API.

    SQL Server Load Soap Api

    ReplyDelete
  4. This is an excellent post I seen thanks to share it. It is really what I wanted to see hope in future you will continue for sharing such a excellent post. จำหน่ายเบสสบู่

    ReplyDelete
  5. How to attach document in SOAP_Request?

    ReplyDelete
  6. How to upload Image file in SOAP request?

    ReplyDelete