之前装了SoapUI,最近装了Postman,分别用它们测试了WebService,下面为用法。

测试的在线WebService(数据来源于中国气象局)
Endpoint: http://www.webxml.com.cn/WebServices/WeatherWebService.asmx 
WSDL: http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl

一、用SoapUI测试
1、菜单栏File -> New SOAP Project -> 打开窗口 -> 
Initial WSDL 输入http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl 
-> OK,SoapUI会自动把所有方法把列出来了。
-> 双击节点getSupportCity下面的Request,自动打开Request 1窗口,如下图

 

2、现在只需在 <web:byProvinceName>?</web:byProvinceName>中输入参数值,如:广东,
点击窗口的三角块,返回结果如下图:

 


二、用Postman测试
1、点击中部的加号,出现Get Untitled Request标签页,如下图

 

2、把Get改成POST,后面输入WebService地址:http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl 
点击下面的Headers,设置Key为Content-Type,Value为text/xml;charset=UTF-8
点击Body,点击raw,在下面输入窗口中,输入SoapUI窗口的请求串:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://WebXml.com.cn/">
   <soapenv:Header/>
   <soapenv:Body>
      <web:getSupportCity>
         <!--Optional:-->
         <web:byProvinceName>广东</web:byProvinceName>
      </web:getSupportCity>
   </soapenv:Body>
</soapenv:Envelope>

说明:

(1) xmlns:web="http://WebXml.com.cn/" 里面地址http://WebXml.com.cn需要和WebService地址保持一致;
(2)xmlns:web的命名空间web需要和下面方法<web:getSupportCity>里面的web保持一致;
(3)getSupportCity为方法名;
(4)byProvinceName为参数;
点击上面的Send按钮,返回结果如下图

 

总结:

在测试WebService方面,用SoapUI非常方便,不单把所有方法把列出来,测试方法时也只需要输入参数值。
Postman测试过程很繁琐,好多地方都需要手动输入。