其实可以用jmeter两种sampler进行webservice的测试:
1、SOAP/XML-RPC Request(但是在jmeter3.2以后版本中已经取消了这个取样器)
2、HTTP请求
下面分别介绍两种方式
一、首先需要使用soupUI工具抓取webservice接口的部分需要的信息。
1、新建项目

2、新建成功的项目信息如下图:

3、选择要测试的接口,右键新建request

4、编辑报文内容,点击左上角的绿色三角执行按钮,右侧窗口查看接口请求结果

5、可以复制下发送的报文的格式
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:web="http://WebXml.com.cn/">
<soap:Header/>
<soap:Body>
<web:getSupportCity>
<!--Optional:-->
<web:byProvinceName>?</web:byProvinceName>
</web:getSupportCity>
</soap:Body>
</soap:Envelope>
二、使用SOAP/XML-RPC Request(但是在jmeter3.2以后版本中已经取消了这个取样器)形式进行测试,以下随便放一张图,因为我用的jmeter版本是3.3,么有SOAP/XML-RPC Request sampler,而是主要用的第二种测试形式。

python
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://WebXml.com.cn/">
<soapenv:Header/>
<soapenv:Body>
<web:getTVstationString>
<web:theAreaID>12</web:theAreaID>
</web:getTVstationString>
</soapenv:Body>
</soapenv:Envelope>
soapaction的地址:为第1行数据和第4行接口的相叠加的内容
1 web="http://WebXml.com.cn/"
4 <web:getTVstationString>
形成地址:http://WebXml.com.cn/getTVstationString
对于公共的webservice接口,可以使用soapUI进行抓取,或者是其他工具去抓取发送报文的格式
三、使用HTTP请求sampler来测试webservice接口
1、建立HTTP请求,如图,请求内容写在BODY DATA里,选择方法为post

python
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<getSupportCity xmlns="http://WebXml.com.cn/">
<byProvinceName>河南</byProvinceName>
</getSupportCity>
</soap:Body>
</soap:Envelope>
2、建立HTTP头信息,如下
Soapaction地址和第一种方法一致

3、接着建立下一个接口请求,方式同上

python
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<getWeatherbyCityName xmlns="http://WebXml.com.cn/">
<theCityName>${b1}</theCityName>
</getWeatherbyCityName>
</soap:Body>
</soap:Envelope>

4、最终执行的请求结果如下图:




最后感谢每一个认真阅读我文章的人,礼尚往来总是要有的,虽然不是什么很值钱的东西,如果你用得到的话可以直接拿走:
这些资料,对于【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴上万个测试工程师们走过最艰难的路程,希望也能帮助到你!
