美文网首页
JMeter测试Web服务(应用案例)

JMeter测试Web服务(应用案例)

作者: 82a7fe2508f4 | 来源:发表于2022-05-31 10:39 被阅读0次

案例说明

这里以天气预报服务为例。

400个国内外主要城市天气预报Web服务访问地址:

Endpoint: http://ws.webxml.com.cn/WebServices/WeatherWebService.asmx

Disco: http://ws.webxml.com.cn/WebServices/WeatherWebService.asmx?disco

WSDL: http://ws.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl

● 操作: getSupportCity

● 功能: 查询本天气预报Web Services支持的国内外城市或地区信息

● 请求方式: HTTP/POST

● 接口地址: http://ws.webxml.com.cn/WebServices/WeatherWebService.asmx

● 输入参数: byProvinceName = 指定的洲或国内的省份,若为ALL或空则表示返回全部城市

● 返回数据: 一个一维字符串数组String(),结构为:城市名称(城市代码)

操作步骤

1.添加线程组;

2.添加HTTP请求取样器并配置;

3.在取样器节点下添加“HTTP Header Manager”并配置;

4.在取样器节点下添加查看结果树;

5.执行看结果。

使用SOAP1.1时配置测试

HTTP请求配置:

1.Server Name or IP: ws.webxml.com.cn

2.Method: POST

3.Path: /WebServices/WeatherWebService.asmx

4.Content encoding: utf-8

5.Body Data:

<?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>

其中"湖南"为传入的参数值(byProvinceName为参数名)

POST请求传递数据为SOAP消息,格式为XML。需要将SOAP消息放入Body Data中发送给服务器,并且需要告诉服务器对应的Content-Type。

故需要添加一个“HTTP Header Manager”配置元件,在其中添加两个首部“Content-Type”与“SOAPAction”,其中“SOAPAction”用来标识SOAP HTTP请求的目的地,其值是个URI地址。在SOAP1.1中这个首部若其值为空串(""),表示SOAP消息的目的地由HTTP请求的URI标识;无值则表示没有指定这条消息的目的地。

1.Content-Type: text/xml; charset=utf-8

2.SOAPAction: "http://WebXml.com.cn/getSupportCity"

配置如下图所示:

使用SOAP1.2时配置测试

HTTP请求配置只需要将Body 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>

<getSupportCity xmlns="http://WebXml.com.cn/">

<byProvinceName>湖南</byProvinceName>

</getSupportCity>

</soap12:Body>

</soap12:Envelope>

需要修改"HTTP Header Manager"配置元件,在SOAP1.2规范中,SOAPAction首部被Content-Type的“action”属性所取代,但其作用和工作原理都没有变化。

Content-Type: application/soap+xml;charset=UTF-8;action="http://WebXml.com.cn/getSupportCity"

配置如下图所示:

相关文章

网友评论

      本文标题:JMeter测试Web服务(应用案例)

      本文链接:https://www.haomeiwen.com/subject/tkhzprtx.html