Fork me on GitHub

【jmeter系列】WebService(soap)请求

一、SOAP Web服务请求组成

  1. Envelope(信封):SOAP消息的最外层包装,用于标识SOAP消息的开始和结束。一个SOAP消息只包含一个Envelope元素。

  2. Header(头部):可选的部分,用于包含与消息相关的元数据信息,如身份验证信息、加密方法等。Header元素是Envelope元素的直接子元素。

  3. Body(消息体):必需的部分,用于封装实际的操作请求或响应数据。Body元素是Envelope元素的直接子元素。

  4. Fault(错误):可选的部分,用于在发生错误时返回错误信息。Fault元素包含了错误码、错误描述等信息,并在Body元素中出现。如果请求未出错,就不包含Fault元素。

  5. SOAP消息的XML结构示例:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
    <soap:Header>
        <!-- 可选的头部信息 -->
    </soap:Header>
    <soap:Body>
        <!-- 请求或响应数据 -->
    </soap:Body>
</soap:Envelope>

在Body中,可以包含一个或多个操作元素,每个操作元素表示一个具体的操作,如"GetCustomers"或"UpdateOrder"。操作元素可以包含输入参数和输出结果。

SOAP消息使用HTTP协议进行传输,通常通过HTTP POST请求发送到Web服务的URL地址,并在请求的Content-Type中指定为"application/soap+xml"。请求的消息体中包含了由Envelope、Header和Body构成的SOAP消息。

服务端接收到请求后,解析SOAP消息,根据消息中的操作信息执行相应的操作。处理完请求后,发送由Envelope、Header和Body构成的SOAP消息作为响应返回给客户端。

二、具体示例

接口练习地址:http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx?op=getMobileCodeInfo

请求参数:

POST /WebServices/MobileCodeWS.asmx HTTP/1.1
Host: ws.webxml.com.cn
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://WebXml.com.cn/getMobileCodeInfo"
 
<?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>
    <getMobileCodeInfo xmlns="http://WebXml.com.cn/">
      <mobileCode>string</mobileCode>
      <userID>string</userID>
    </getMobileCodeInfo>
  </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>
    <getMobileCodeInfoResponse xmlns="http://WebXml.com.cn/">
      <getMobileCodeInfoResult>string</getMobileCodeInfoResult>
    </getMobileCodeInfoResponse>
  </soap:Body>
</soap:Envelope>

 

 

  

  

 

posted @ 2023-07-29 21:20  橘子偏爱橙子  阅读(731)  评论(0编辑  收藏  举报