这里的URL需要自己填写,地址就是SoapUI中地址栏显示的内容,SOAP Action可以填也可以不填,如果需要填写,需要在SoapUI中查看该请求的Action,并且复制到这里。单击OK按钮后形成SOAP请求函数代码:
soap_request("StepName=SOAP Request", "URL=http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx", "SOAPEnvelope=" "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:web=\"http://WebXml.com.cn/\">" "<soapenv:Header></soapenv:Header>" "<soapenv:Body>" "<web:getSupportCityString>" "<web:theRegionCode>?</web:theRegionCode>" "</web:getSupportCityString>" "</soapenv:Body>" "</soapenv:Envelope>", "SOAPAction=", "ResponseParam=response", "Snapshot=t1320736948.inf", LAST); |
这里的<web:theRegionCode>?</web:theRegionCode>是需要输入的内容,也就是我们需要查询的城市编号,所以修改问号为“上海”,运行代码检查返回:
Action.c(4): Notify: Saving Parameter "response = <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><getSupportCityStringResponse xmlns="http://WebXml.com.cn/"><getSupportCityStringResult> <string>鏃犲煄甯\x82,000000</string> </getSupportCityStringResult></getSupportCityStringResponse></soap:Body></soap:Envelope>". |
我们会发现返回并没有出现前面标准的城市信息,而是返回了“鏃犲煄甯\x82,000000”,转码后是无城市\x00,000000,也就是说我们发送的内容服务器能够接受但是没有匹配记录。在XML数据包中由于LR无法按照XML说明中的格式进行转化,经常会出现由于错误转码而无法完成业务的情况,在这里也是因为这个问题。
lr_convert_string_encoding("鏃犲煄甯\x82",LR_ENC_UTF8 ,LR_ENC_SYSTEM_LOCALE,"test"); lr_convert_string_encoding("上海",LR_ENC_SYSTEM_LOCALE,LR_ENC_UTF8,"test"); |
这两行代码在我们开发XML请求时会经常用到,帮助我们把UTF-8的格式换成系统格式,或把系统当前格式转换为UTF-8格式。
这里我们需要得到“上海”的UTF-8编码,然后将编码后的内容作为函数soap_request的一部分发送给服务器,修改代码为:
soap_request("StepName=SOAP Request", "URL=http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx", "SOAPEnvelope=" "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:web=\"http://WebXml.com.cn/\">" "<soapenv:Header></soapenv:Header>" "<soapenv:Body>" "<web:getSupportCityString>" "<web:theRegionCode>涓婃捣</web: theRegionCode>"//上海 "</web:getSupportCityString>" "</soapenv:Body>" "</soapenv:Envelope>", //"SOAPAction=http://WebXml.com.cn/WeatherWSSoap/getSupportCityStringRequest", "ResponseParam=response","Snapshot=t1320736948.inf",LAST); |
检查返回和前面WSDL的方式结果相同,同样的方式可以完成后面的数据分离,该城市的天气情况查询,具体内容这里就不详述了。
在这两种Web Service脚本开发中,WSDL导入方式是开发最为简单的方式,基于SOAP的方式就相对来说自己要处理很多东西,但是当没有WSDL文件时,SOAP基本是唯一的实现方式。这两种模式都是需要对应的License。如果只有Web的License怎么办呢?既然SOAP是用HTTP协议的XML数据格式,那么我们使用HTTP协议也是可以直接模拟的。接着我们来看看如何使用HTTP协议完成Web Service调用。
(未完,精彩待续)
连载一 连载二 连载三 连载四 连载五 连载六 连载七 连载八 连载九 连载十
连载十一 连载十二 连载十三 连载十四 连载十五 连载十六 连载十七 连载十八
本文选自《51Testing软件测试作品系列》之十——《性能测试进阶指南——LoadRunner11实战》。
本站经电子工业出版社和作者的授权,近期将进行部分章节的连载,敬请期待!
版权声明:51Testing软件测试网获电子工业出版社和作者授权连载本书部分章节。
任何个人或单位未获得明确的书面许可,不得对本文内容复制、转载或进行镜像,否则将追究法律责任。
相关阅读: