JMeter中的SOAP/XML-RPC请求元素(SOAP/XML-RPC Request)是用来做什么的?

JMeter中的SOAP/XML-RPC请求元素(SOAP/XML-RPC Request)用于发送SOAP请求来测试SOAP Web服务。

使用SOAP/XML-RPC请求元素需要配置以下参数:

  1. Web服务WSDL地址,例如:http://www.testwebservicex.net/testglobalweather.asmx?WSDL
  2. SOAP操作名称,对应WSDL文件中定义的操作,例如GetWeather。
  3. SOAP请求消息,需要与WSDL文件中操作的请求消息匹配。可以输入XML内容或从文件中获取。

例如:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"   
xmlns:web="http://www.webservicex.net/">
<soapenv:Header/>
<soapenv:Body>
<web:GetWeather>  
<web:CityName>London</web:CityName>
<web:CountryName>UK </web:CountryName>
</web:GetWeather>
</soapenv:Body>
</soapenv:Envelope>  

使用SOAP/XML-RPC请求元素可以实现以下测试场景:

  • 函数测试:测试各个SOAP操作是否正常。
  • 负载测试:可以添加多个线程组,设置高并发来进行压力测试。
  • 参数化测试:通过使用变量和循环控制器对CityName等参数进行遍历。
  • 集成测试:可以添加多个SOAP请求测试服务间的集成。

一个简单的示例:

线程组:
线程数:1

测试片段:  

SOAP/XML-RPC请求:
地址:http://www.testwebservicex.net/testglobalweather.asmx?WSDL
操作名称: GetWeather  

SOAP消息请求:
<soap:Envelope>
......  
</soap:Envelope>

响应断言:  
响应包含:London  

逻辑控制器(If Controller):
如果响应包含London则执行:  

SOAP/XML-RPC请求:  
地址:http://www.testwebservicex.net/testglobalweather.asmx?WSDL
操作名称:GetWeather   

SOAP消息请求:
<soap:Envelope>  
...... 
</soap:Envelope>  

运行测试计划,会先发送GetWeather请求,判断包含London,然后再发送一个GetWeather请求。
SOAP/XML-RPC请求元素允许我们通过JMeter轻松实现对SOAP Web服务的测试。