最近处理一个webservice接口,需要对它的返回值进行校验,成功or失败。
1、首先管理webservice服务,加入进去,把入参和返回值都加上
web_service_call( "StepName=服务名_101",
"SOAPMethod=服务连接地址",
"ResponseParam=response",
"Service=服务名",
"ExpectedResponse=SoapResult",
"Snapshot=t1630566956.inf",
BEGIN_ARGUMENTS,
"arg0=入参",
END_ARGUMENTS,
BEGIN_RESULT,
"return=Param_return",//返回值
END_RESULT,
LAST);
2、对返回值进行判断,用这个函数strstr()下面看示例
if(strstr(lr_eval_string("{Param_return}"),"成功")>0){//判断是否存在这个字符
lr_end_transaction("插入",LR_AUTO);
return 0;
}else{
lr_error_message("事务失败------!");//打印错误日志
lr_end_transaction("插入",LR_FAIL);
return 0;
}
3、输出的日志是这样的:
Action.c(5): 通知: 正在保存参数“服务_101_Response = <服务><return>{"state":"B00001","reason":"客户校验:此客户是失效客户!","length":0.0,"width":0.0,"height":0.0}</return></blendPostWaybill>”。
Action.c(5): 通知: 正在保存参数“response = <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:blendPostWaybillResponse xmlns:ns2="http://blendpostservice.webservice.pickup.jdpt.chinapost.cn/"><return>{"state":"B00001","reason":"瀹㈡埛鏍¢獙锛氭瀹㈡埛鏄け鏁堝鎴凤紒","length":0.0,"width":0.0,"height":0.0}</return></ns2:blendPostWaybillResponse></soap:Body></soap:Envelope>”。
Action.c(5): 通知: 正在保存参数“Param_return = {"state":"B00001","reason":"客户校验:此客户是失效客户!","length":0.0,"width":0.0,"height":0.0}”。
Action.c(5): Web 服务调用 "服务_101" 成功
Action.c(19): 通知: 参数替换:参数“Param_return”=“{"state":"B00001","reason":"客户校验:此客户是失效客户!","length":0.0,"width":0.0,"height":0.0}”
Action.c(29): 错误: 事务失败------!
Action.c(30): 通知: 事务"收寄"以"Fail"状态结束 (持续时间: 4.0147 浪费时间: 2.2169)。
Action.c(30): 通知: 事务"收寄"具有 1 条错误消息。
Action.c(30): 通知: 与事务"收寄"关联的 1st 错误消息为"错误 0: 事务失败------!"
4、controller里面还有一个设置,我是12.53版本(针对webservice脚本,http协议脚本还没关注这个项),在run-setting里面,【常规】->【其他】->【当调用lr_error_message时,将打开的事务设置为失败】,这个在压测的时候,就可以屏蔽掉失败的事务