1. 程式人生 > >Jmeter實現webservice協議的指令碼

Jmeter實現webservice協議的指令碼

1. 開啟Jmeter,新建執行緒組,並新增一個SOAP/XML-RPC Request取樣器。

2. 在URL輸入欄輸入地址:http://www.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl

3. 在Send SOAPAction輸入欄輸入選擇的介面的soapaction,如http://WebXml.com.cn/getWeather

以下為getWeather:

SOAP 1.1

以下是 SOAP 1.2 請求和響應示例。所顯示的佔位符需替換為實際值。

POST /WebServices/WeatherWS.asmx HTTP/1.1
Host: www.webxml.com.cn
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://WebXml.com.cn/getWeather" <?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> <getWeather xmlns="http://WebXml.com.cn/"> <theCityCode>string
</theCityCode> <theUserID>string</theUserID> </getWeather> </soap:Body> </soap:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?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>
    <getWeatherResponse xmlns="http://WebXml.com.cn/">
      <getWeatherResult>
        <string>string
</string> <string>string</string> </getWeatherResult> </getWeatherResponse> </soap:Body> </soap:Envelope>

 

SOAP 1.2

以下是 SOAP 1.2 請求和響應示例。所顯示的佔位符需替換為實際值。

POST /WebServices/WeatherWS.asmx HTTP/1.1
Host: www.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>
    <getWeather xmlns="http://WebXml.com.cn/">
      <theCityCode>string</theCityCode>
      <theUserID>string</theUserID>
    </getWeather>
  </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>
    <getWeatherResponse xmlns="http://WebXml.com.cn/">
      <getWeatherResult>
        <string>string</string>
        <string>string</string>
      </getWeatherResult>
    </getWeatherResponse>
  </soap12:Body>
</soap12:Envelope>

4. 在Soap /XML-RPC 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>
    <getWeather xmlns="http://WebXml.com.cn/">
      <theCityCode>2013</theCityCode>
      <theUserID></theUserID>
    </getWeather>
  </soap:Body>
</soap:Envelope>

輸入內容已經將城市程式碼替換。

5. 新增一個響應斷言,響應欄位選擇“響應文字”,匹配規則選擇“包括”,新增測試的模式,輸入“上海”。

6. 新增檢視結果樹,可檢視伺服器返回資料。