【WebService】通過postman請求web service
阿新 • • 發佈:2020-12-22
概述
用postman請求web service,在編寫soap xml時,要區分soap(或http)的版本,不同的版本,有不同的請求方式。
具體寫法參考這個文章標籤下的其他文章。
解決方法
以soap1.1為例
1、postman用post方式,header上要設定:Content-Type:text/xml;charset=utf-8
2.請求報文體選擇,body -> raw -> xml
3.請求報文
以版本1.1為例,請求報文有兩種寫法
方法一
<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:cxf3="http://cxf3.what21.com/" xmlns:aa="http://webservice.example.com/"> <soap:Body> <aa:sayHello> <userName>青山</userName> </aa:sayHello> </soap:Body> </soap:Envelope>
方法二
<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:cxf3="http://cxf3.what21.com/"> <soap:Body xmlns:aa="http://webservice.example.com/"> <aa:sayHello> <userName>青山</userName> </aa:sayHello> </soap:Body> </soap:Envelope>
其中,
xmlns:aa 屬性的內容是服務端配置的名稱空間(即,@WebService註解的targetNamespace屬性),通過訪問wsdl文件,也可以看到。
請求報文中xml的約束中,只有xmlns:soap和自定義(xmlns:aa)的名稱空間(最)有用.
<aa:sayHello>是方法名,具體的說,只有sayHello是方法名。
<userName>是方法引數名,也是@WebParam()中name屬性的設定值;而且不能加 aa: 這個字首。