Jmeter发送SOAP请求对WebService接口测试

本文介绍如何利用JMeter工具发送SOAP请求,对WebService接口进行全面的功能和性能测试,详细阐述了测试步骤和配置过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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:
在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信息头管理器


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





评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值