加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

loadrunner 测试webservice之二:通过soap_reuest

发布时间:2020-12-16 23:09:14 所属栏目:安全 来源:网络整理
导读:????之前文章写了一半,保存草稿后,最后发现全没有了,只好重新来写,这次也就不那么?嗦了,主要把测试的步骤分享下。 ????LoadRunner测试webservice共有3种方式:1、通过web_service_call函数,也就是导入wsdl文件或者URL的方式;2、通过soap_request函数

????之前文章写了一半,保存草稿后,最后发现全没有了,只好重新来写,这次也就不那么?嗦了,主要把测试的步骤分享下。

????LoadRunner测试webservice共有3种方式:1、通过web_service_call函数,也就是导入wsdl文件或者URL的方式;2、通过soap_request函数,通过导入xml文件来实现;3、通过http协议来手写脚本来实现。

????第一种可以访问:http://www.voidcn.com/article/p-xiuusyyg-pa.html

????今天的重点是第二种,通过Import SOAP来导入xml文件,从而实现对webservice接口的调用。

下面以大家都熟知的天气预报为例:

????天气预报的接口URL:http://webservice.webxml.com.cn/webservices/weatherwebservice.asmx

调用getWeatherbyCityName方法。

打开http://webservice.webxml.com.cn/webservices/weatherwebservice.asmx?op=getWeatherbyCityName 页面,如下图所示:

?

?

?

将下面红框的部分保存到xml文件中,导入刚才的XML文件,如下图所示:

?

导入后自动生成以下代码:

soap_request("StepName=SOAP Request",??????????
??"URL=http://webservice.webxml.com.cn/webservices/weatherwebservice.asmx",??????????
??"SOAPEnvelope="
??"<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">"
???"<soap12:Body>"
????"<getWeatherbyCityName xmlns="http://WebXml.com.cn/">"
?????"<theCityName>string</theCityName>"?????????????????????????//这里填写城市的名字
????"</getWeatherbyCityName>"
???"</soap12:Body>"
??"</soap12:Envelope>",??????????
??"SOAPAction=getWeatherbyCityName",??????????
??"ResponseParam=response",??????????
??"Snapshot=t1418827945.inf",????????????
??LAST);

?

然后在刚才生成的代码前,增加header信息。需要增加的内容见第一个图中,其中,“Content-Length”不需要加。

在该例子中需要增加的代码如下:

web_add_header("POST",
?????? "/WebServices/WeatherWebService.asmx HTTP/1.1");
?web_add_header("Host",
?????? "webservice.webxml.com.cn");
?web_add_header("Content-Type",
?????? "application/soap+xml; charset=utf-8");???????????????????????????????//这里注意和截图里有些不同
?web_add_header("SOAPAction",
?????? ""http://WebXml.com.cn/getWeatherbyCityName"");

?

这样简单的通过soap_request函数测试Webservice的方式就完成了。

?

取到WebService返回的XML数据后,可以使用XPath的方式验证数据,LR提供了几个处理XML的函数:

lr_xml_get_values()? //Retrieves values of XML elements found by a query

lr_xml_set_values()? //Sets the values of XML elements found by a query

lr_xml_extract()? //Extracts XML string fragments from an XML string

lr_xml_delete()? //Deletes fragments from an XML string

lr_xml_replace()? //Replaces fragments of an XML string

lr_xml_insert()? //Inserts a new XML fragment into an XML string

lr_xml_find()? //Verifies that XML values are returned by a query

lr_xml_transform()? //Applies Extensible Stylesheet Language (XSL) Transformation to XML data

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读