Jmeter也可以对WebService接口测试。本次测试的接口是:
getSupportCityString
获得支持的城市/地区名称和与之对应的ID
输入参数:theRegionCode = 省市、国家ID或名称,返回数据:一维字符串数组。
示例:
SOAP 1.2
以下是 SOAP 1.2 请求和响应示例。所显示的
占位符
需替换为实际值。
POST /WebServices/WeatherWS.asmx HTTP/1.1
Host: ws.webxml.com.cn
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<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>
<getSupportCityString xmlns="http://WebXml.com.cn/">
<theRegionCode>string</theRegionCode>
</getSupportCityString>
</soap12:Body>
</soap12:Envelope>
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<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>
<getSupportCityStringResponse xmlns="http://WebXml.com.cn/">
<getSupportCityStringResult>
<string>string</string>
<string>string</string>
</getSupportCityStringResult>
</getSupportCityStringResponse>
</soap12:Body>
</soap12:Envelope>
Step1:
添加线程组,并添加SOAP/XML-RPC Request Sampler。

Step2:
在URL中填写测试地址:
http://ws.webxml.com.cn/WebServices/WeatherWS.asmx
在Soap/XML-RPC Data中输入:
<?xml version="1.0" encoding="utf-8"?>
<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>
<getSupportCityString xmlns="http://WebXml.com.cn/">
<theRegionCode>string</theRegionCode>
</getSupportCityString>
</soap12:Body>
</soap12:Envelope>
在发送的信息中,要填写真正的参数替换占位符<theRegionCode>string</theRegionCode>
为TestPlan添加用户定义的变量

最终发送的数据为
<theRegionCode>${RegionCode}</theRegionCode>

Step3:
在监听器中插入查看结果树。
发送请求后会发现响应数据错误,提示“服务器未能识别 HTTP 头 SOAPAction 的值: ”

这是因为服务器不知道以何种类型来解析请求数据,才导致没有正确的数据返回。
所以在发送请求之前,还有一个重要的步骤,就是添加
HTTP信息头管理器

再次发送数据,可以成功获取城市代码。
