You can use either of the following methods to test the Web Services program using LoadRunner: web_service_call () and soap_request (). The use of the two is very familiar, we use the web services protocol for recording. The following describes the usage:
1. web_service_call ()The procedure is as follows:
1. Save the WSDL file. Open the web services address in IE and add "? WSDL ".For example, "http: // 192.168.4.112: 8082/edaser... neservice. asmx? WSDL ". Save the opened XML file as a file with the extension ". WSDL. For example
2. Import the saved WSDL file in LoadRunner,For example
3. added the call function,For example
4. The following code is automatically generated.
Web_service_call ("stepname = runservice_101 ",
"Soapmethod = serviceengineservice | serviceengineservicesoap | runservice ",
"Responseparam = response ",
"Service = serviceengineservice ",
"Expectedresponse = soapresult ",
"Snapshot = t00003650512.inf ",
Begin_arguments,
"XML: indatabuf ="
"<Indatabuf>"
<Servicename> 2307 </servicename>"
"<Servicetype> 3 </servicetype>"
"<Pageno> </pageno>"
"<Sessionid> </sessionid>"
"<Xmldata> <dataset> </xmldata>"
"</Indatabuf> ",
End_arguments,
Begin_result,
"Runserviceresult = param_runserviceresult ",
End_result,
Last );
Lr_log_message ("result = % s", lr_eval_string ("{param_runserviceresult }"));-- Return values can be output.
Ii. soap_request (),The procedure is as follows:
1. Define the SOAP request file.Open the Web Services page in IE, such as http: // 192.168.4.112: 8082/edaser... asmx? OP = runservice. IE will display the information of this file and copy and save it as an XML file.
2. Import the XML file just defined.
3. the following code is automatically generated after the import.
Soap_request ("stepname = SOAP request ",
"Url = http: /// 192.168.4.112: 8082/edaservice/serviceengineservice. asmx ",
"Soapenvelope ="
"<? XML version = \ "1.0 \" encoding = \ "UTF-8 \"?> "
"<Soap12: envelope xmlns: xsi = \" comment "xmlns: XSD = \" http://www.w3.org/2001/xmlschema\ "xmlns: soap12 = \" comment ">"
"<Soap12: Body>"
"<Runservice xmlns = \" http: // 192.168.4.112/\ ">"
"<Indatabuf>"
"<Servicename> 2307 </servicename>" -- the input parameter must be set to the value you need.
"<Servicetype> 3 </servicetype>" -- the input parameter must be set to the value you need.
"<Pageno> </pageno>"
"<Sessionid> </sessionid>"
"<Xmldata> </xmldata>"
"</Indatabuf>"
"</Runservice>"
"</Soap12: Body>"
"</Soap12: envelope> ",
"Soapaction = runservice ",
"Responseparam = response ",
"Snapshot = t00003722181.inf ",
Last );
4. Add the header information before the automatically generated code.For more information, see step 1. "Content-Length" does not need to be added. The code we added in this example is:
Web_add_header ("Post ",
"/Edaservice/serviceengineservice. asmx HTTP/1.1 ");
Web_add_header ("host ",
"192.168.4.112 ");
Web_add_header ("Content-Type ",
"Application/soap + XML; charset = UTF-8 ");
The two methods are described.
Note:
1. If the input parameter string needs to use "<" or ">", you must pass "& L t;" or"& G t;"(Spaces are required for these characters)
2. If the Web Services returns an XML file, you can use lr_xml_get_values to obtain it.For example:
Int numofvalues;
Numofvalues = lr_xml_get_values ("xml = {response}", -- response is the return value of the soap_request Function
"Valueparam = outputparam", -- defines the return value of lr_xml_get_values
"Query =/soap: envelope/soap: body/helloworldresponse/helloworldresult", -- Name of the XML node, which must contain the name of the parent node and be separated.
"Selectall = yes", last );
For (I = 0; I <numofvalues; I ++) {/* print multiple values of outputparam */-- output the XML value just obtained
Sprintf (BUF, "{outputparam _ % d}", I + 1 );
Lr_output_message ("result = % s", lr_eval_string (BUF ));
Re = strncmp (lr_eval_string (BUF), string1, 85 );
Lr_output_message ("Return: % d", RE );
}
3. You can switch to the tree interface to view the request of the defined function and the return value of the server.