JMeter发送SOAP接口协议

一、SOAP 协议简介

SOAP(Simple Object Access Protocol), 简单对象访问协议,它是交换数据的一种协议规范,是一种轻量的、简单的、基于XML(标准通用标记语言下的一个子集)的协议,它被设计成在WEB上交换结构化的和固化的信息。

SOAP 通讯协议使用 HTTP 来发送XML 格式的信息,SOAP 把 XML 的使用代码化为请求和响应参数编码模式, 并用HTTP 作传输。

二、HTTP 取样器发送接口请求

1、SOAP 1.1版本

以下是 SOAP 1.1 请求接口及其参数

#主机
www.webxml.com.cn

#接口
/WebServices/WeatherWS.asmx/getRegionCountry

#请求方式
POST

#请求头
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://WebXml.com.cn/getRegionCountry"

#请求参数
<?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>
    <getRegionCountry xmlns="http://WebXml.com.cn/" />
  </soap:Body>
</soap:Envelope>

http请求及请求头的构造

请求结果

2、SOAP 1.2版本

以下是 SOAP 1.2 请求接口及其参数

#主机
www.webxml.com.cn

#接口
/WebServices/WeatherWS.asmx/getRegionCountry

#请求方式
POST

#请求头
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>
    <getRegionCountry xmlns="http://WebXml.com.cn/" />
  </soap12:Body>
</soap12:Envelope>

http请求及请求头的构造

请求结果

3、SOAP 1.1与1.2区别

  • 请求头的区别

    • content-Type不同,如图所示;
    • 1.1版本请求头中多了SOAPAction参数;

  • 请求参数区别:主要是1.2版本中参数标签变为了soap12。

总之,用HTTP 取样器发送SOAP协议请求时,请求头一般都会有 Content-type: application/xml ,因为SOAP协议请求数据就是 XML 格式。

三、Custom SOAP Sampler 插件发送请求

1、插件安装

启动jmeter的GUI,点击选择Options,可以看到已经安装好的插件管理工具Plugins Manager插件管理界面,搜索 Custom SOAP Sampler,勾选它,然后点击安装。

安装后,重启jmeter,然后可以看到安装结果。在监听器中,可以查看到已安装好的插件。

如果在插件管理器中安装不成功,则可以自己在网上下载一个CustomSoapSampler-1.3.3.jar

然后,放进D:\apache-jmeter-5.5\lib\ext目录下。最后,重启JMeter就可以看到plugins-manager中已安装该插件。如图所示:

2、Custom SOAP Sampler 插件发送请求

以下是 SOAP 1.2 请求接口及其参数

#主机
www.webxml.com.cn

#接口
/WebServices/WeatherWS.asmx/getRegionCountry

#请求方式
POST

#请求头
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>
    <getRegionCountry xmlns="http://WebXml.com.cn/" />
  </soap12:Body>
</soap12:Envelope>

http请求及请求头的构造

请求结果:

四、参考

1、SOAP协议接口:http://www.webxml.com.cn/WebServices/WeatherWS.asmx?op=getRegionCountry

2、Custom SOAP Sampler 插件下载:https://github.com/spinning10/JMeterSoapSampler/blob/master/target/CustomSoapSampler-1.3.jar

posted @ 2022-11-09 18:12  xyztank  阅读(349)  评论(0)    收藏  举报