1. 程式人生 > >Jmeter傳送SOAP請求對WebService介面測試

Jmeter傳送SOAP請求對WebService介面測試

Jmeter也可以對WebService介面測試。本次測試的介面是: getSupportCityString 獲得支援的城市/地區名稱和與之對應的ID 輸入引數:theRegionCode = 省市、國家ID或名稱,返回資料:一維字串陣列。 示例: SOAP 1.2 以下是 SOAP 1.2 請求和響應示例。所顯示的佔位符需替換為實際值。 POST /WebServices/WeatherWS.asmx HTTP/1.1 Host: ws.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> <getSupportCityString xmlns="http://WebXml.com.cn/"> <theRegionCode>string</theRegionCode> </getSupportCityString> </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> <getSupportCityStringResponse xmlns="http://WebXml.com.cn/"> <getSupportCityStringResult> <string>string</string> <string>string</string> </getSupportCityStringResult> </getSupportCityStringResponse> </soap12:Body>

</soap12:Envelope>


Step1: 新增執行緒組,並新增SOAP/XML-RPC Request Sampler。
Step2: 在Soap/XML-RPC 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> <getSupportCityString xmlns="http://WebXml.com.cn/"> <theRegionCode>string</theRegionCode> </getSupportCityString> </soap12:Body> </soap12:Envelope> 在傳送的資訊中,要填寫真正的引數替換佔位符<theRegionCode>string</theRegionCode> 為TestPlan新增使用者定義的變數

最終傳送的資料為 <theRegionCode>${RegionCode}</theRegionCode>
Step3: 在監聽器中插入檢視結果樹。 傳送請求後會發現響應資料錯誤,提示“伺服器未能識別 HTTP 頭 SOAPAction 的值: ”
這是因為伺服器不知道以何種型別來解析請求資料,才導致沒有正確的資料返回。 所以在傳送請求之前,還有一個重要的步驟,就是新增HTTP資訊頭管理器
再次傳送資料,可以成功獲取城市程式碼。