Loadrunner测试webservice接口
转:http://blog.csdn.net/liu870915/article/details/52066517
方法一:土办法是使用LR自带的webservice协议,按照向导的提示:导入wsdl、选择服务名、形成脚本的框架、读懂并设定参数值,参照log返回信息,调试脚本,很简单,这里就不多讲了........
方法二:利用LR的web(http/html)协议自带的web_custom_request()函数,向指定的URL地址POST相应的SOAP协议的HTTP消息,LR function reference对web_custom_request()函数的解释和示例,简直是悲剧,下面首先给出根据wsdl文件生成SOAP消息的方法,然后给出函数示例:
SOAP协议本身,这里就不累赘了,根据wsdl文件生成SOAP消息可以借助工具XMLSpy这类的工具,它通过导入wsdl文件,建立相应服务的SOAP请求,示例如下:
http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<m:r11OrderReq xmlns:m="http://service.intf.vsop.bss">
<m:in0>String</m:in0>
</m:r11OrderReq>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
下面给出函数示例:
http://133.37.51.126:7010/xxxxxx/xxxxxx/xxxxxx", "service");//lc
lr_start_transaction("xxxxxxx");
"URL={service}",
"Method=POST",
"Resource=0",
"RecContentType=text/xml",
"Referer=",
"Snapshot=t1.inf",
"Mode=HTML",
"EncType=text/xml;charset=utf-8",
"Body=<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\"
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"<
CDATA>10000000000172010-4-13'>http://service.intf.vsop.bss\"><m:in0><![CDATA[<WorkListFKToVSOPReq><streamingNo>1000000000017</streamingNo><TimeStamp>2010-4-1314:00:01</TimeStamp><OrderId>1200000000000017</OrderId><SystemId>FK</SystemId><ActionType>0</ActionType><ProdSpecCode>CDMA</ProdSpecCode><ProductNo>18982765613</ProductNo><UserState>1</UserState></WorkListFKToVSOPReq>]]></m:in0></m:r11OrderReq></SOAP-ENV:Body></SOAP-ENV:Envelope>",
LAST);
if(strcmp(lr_eval_string("{rspcode}") ,"0")) {
//lr_error_message("xxxxxxx fail:%s", lr_eval_string("{rspcode}" ));
lr_error_message("xxxxxxx fail");
}
ps:在<![CDATA]>标记下,所有的标记、实体引用都被忽略,而被XML处理程序一视同仁地当做字符数据看待。