WSDL測試webservice接口記錄

收到一個事情,須要對接第三方API,對方給了個service,看了一下,原來是webservices的。html

上一次測試webervice的接口,仍是至少八九年前的時候了,這種相對比較老舊的也很久不在使用。java

因而,簡單搞了一下,從搭環境到測試完成,基本花了10來分鐘,對比結果花點時間,也抽空簡單記錄一下。 web

請求:json

http://www.shuce.com.cn/services/CommService?wsdl

接口:call瀏覽器

參數:工具

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://service.shuce.com.cn">
<soapenv:Header/>
<soapenv:Body>
<ser:call>
<ser:act>dscx_lz</ser:act>
<!--1 or more repetitions:-->
<ser:args>74481885-4244-47d9-aa51-88e2aabebdbc</ser:args>
<ser:args>cxveh</ser:args>
<ser:args>C372DD</ser:args>
<ser:args>02</ser:args>
</ser:call>    
</soapenv:Body>
</soapenv:Envelope>

 

返回:測試

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<callResponse xmlns="http://service.shuce.com.cn">
<callReturn>{"ret":1,"clpp":"寶馬牌","clxh":"BMW7202ES(BMWX1)","gcjk":"國產","zzg":"中國","zzcmc":"華晨寶馬汽車有限公司","fdjxh":"N46B20E","hdzk":"5","ckg":"4477*1798*1577","csys":"棕","rlzl":"汽油","pl":"1995","gl":"122","cllx":"小型轎車","syxz":"非營運","ccdjrq":"20130917","zt":"正常","hbdbqk":"GB18352.3-2005(國Ⅳ階段)","ccrq":"20130522","yxqz":"20190930","qzbfqz":"20991231"}
</callReturn>
</callResponse>
</soapenv:Body>
</soapenv:Envelope>

 

json格式化結果:ui

{
"ret": 1,
"clpp": "寶馬牌",
"clxh": "BMW7202ES(BMWX1)",
"gcjk": "國產",
"zzg": "中國",
"zzcmc": "華晨寶馬汽車有限公司",
"fdjxh": "N46B20E",
"hdzk": "5",
"ckg": "4477*1798*1577",
"csys": "棕",
"rlzl": "汽油",
"pl": "1995",
"gl": "122",
"cllx": "小型轎車",
"syxz": "非營運",
"ccdjrq": "20130917",
"zt": "正常",
"hbdbqk": "GB18352.3-2005(國Ⅳ階段)",
"ccrq": "20130522",
"yxqz": "20190930",
"qzbfqz": "20991231"
}

 

其餘spa

後來,我看了一下別的wsdl:.net

http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?wsdl

作了一個測試,結果測試OK,簡要也記錄一下

request:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://WebXml.com.cn/">
   <soapenv:Header/>
   <soapenv:Body>
      <web:getCountryCityByIp>
         <!--Optional:-->
         <web:theIpAddress>115.239.210.27</web:theIpAddress>
      </web:getCountryCityByIp>
   </soapenv:Body>
</soapenv:Envelope>

response:

<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">
   <soap:Body>
      <getCountryCityByIpResponse xmlns="http://WebXml.com.cn/">
         <getCountryCityByIpResult>
            <string>115.239.210.27</string>
            <string>浙江省紹興市 電信</string>
         </getCountryCityByIpResult>
      </getCountryCityByIpResponse>
   </soap:Body>
</soap:Envelope>

...

若是你想要嘗試一下,進行一些測試,這裏提供了一些wsdl,能夠用來測試,能夠試試。

 

所謂授之以魚,不如授之以漁。這裏也補上一些前提和方法:

下載地址:

官網:https://www.soapui.org/professional/soapui-pro.html

文件地址:http://cncspace.onlinedown.net/down/SoapUI-5.2.1-mac-bin.zip

下載地址:http://www.onlinedown.net/soft/177299.htm

下載以後的安裝很簡單,略過,簡要提一下啓動。若是用的是mac的話,這樣啓動:

啓動命令:

cd /Users/hao/Downloads/SoapUI-5.2.1-mac-bin/SoapUI-5.2.1/bin
./soapui.sh

haodeMBP:bin hao$ pwd

/Users/hao/Downloads/SoapUI-5.2.1-mac-bin/SoapUI-5.2.1/bin

haodeMBP:bin hao$ ls

SoapUI-Spashscreen.png installationcomplete.sh mockservicerunner.sh soapui-errors.log soapui.sh toolrunner.sh wargenerator.sh

actions listeners securitytestrunner.sh soapui-log4j.xml starter-page.html uninstallactiontrack.sh

ext loadtestrunner.sh soapui-5.2.1.jar soapui.log testrunner.sh updateinstallation.sh

haodeMBP:bin hao$ ./soapui.sh 

================================

=

= SOAPUI_HOME = /Users/hao/Downloads/SoapUI-5.2.1-mac-bin/SoapUI-5.2.1

=

================================

Configuring log4j from [/Users/hao/Downloads/SoapUI-5.2.1-mac-bin/SoapUI-5.2.1/bin/soapui-log4j.xml]

16:26:15,406 INFO  [DefaultSoapUICore] Creating new settings at [/Users/hao/soapui-settings.xml]

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".

SLF4J: Defaulting to no-operation (NOP) logger implementation

SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

16:26:16,523 INFO  [PluginManager] 0 plugins loaded in 3 ms

16:26:16,523 INFO  [DefaultSoapUICore] All plugins loaded

Configuring log4j from [/Users/hao/Downloads/SoapUI-5.2.1-mac-bin/SoapUI-5.2.1/bin/soapui-log4j.xml]

16:26:16,729 INFO  [DefaultSoapUICore] Creating new settings at [/Users/hao/soapui-settings.xml]

16:26:16,740 INFO  [PluginManager] 0 plugins loaded in 0 ms

16:26:16,740 INFO  [DefaultSoapUICore] All plugins loaded

16:26:23,688 INFO  [DefaultSoapUICore] Defaulting to native L&F for Mac OS X

16:26:23,740 INFO  [SoapUI] Used java version: 1.8.0_181

16:28:17,764 INFO  [SchemaUtils] Added default schema from file:/Users/hao/Downloads/SoapUI-5.2.1-mac-bin/SoapUI-5.2.1/bin/soapui-5.2.1.jar!/com/eviware/soapui/resources/xsds/xop.xsd with targetNamespace http://www.w3.org/2004/08/xop/include

16:28:17,781 INFO  [SchemaUtils] Added default schema from file:/Users/hao/Downloads/SoapUI-5.2.1-mac-bin/SoapUI-5.2.1/bin/soapui-5.2.1.jar!/com/eviware/soapui/resources/xsds/XMLSchema.xsd with targetNamespace http://www.w3.org/2001/XMLSchema

16:28:17,782 INFO  [SchemaUtils] Added default schema from file:/Users/hao/Downloads/SoapUI-5.2.1-mac-bin/SoapUI-5.2.1/bin/soapui-5.2.1.jar!/com/eviware/soapui/resources/xsds/xml.xsd with targetNamespace http://www.w3.org/XML/1998/namespace

16:28:17,782 INFO  [SchemaUtils] Added default schema from file:/Users/hao/Downloads/SoapUI-5.2.1-mac-bin/SoapUI-5.2.1/bin/soapui-5.2.1.jar!/com/eviware/soapui/resources/xsds/swaref.xsd with targetNamespace http://ws-i.org/profiles/basic/1.1/xsd

16:28:17,783 INFO  [SchemaUtils] Added default schema from file:/Users/hao/Downloads/SoapUI-5.2.1-mac-bin/SoapUI-5.2.1/bin/soapui-5.2.1.jar!/com/eviware/soapui/resources/xsds/xmime200505.xsd with targetNamespace http://www.w3.org/2005/05/xmlmime

可見啓動以後,就打開了對應的應用程序窗口。

至於工具的使用,我向來以爲是不用看教程,任何工具拿上來隨便點兩下,就明白了,這個soapUI也是同樣的。


 

其實方法這裏已經寫的很清楚了,並且沒什麼問題。照着操做便可。

以上是原創,下面這一段是摘錄的。

測試操做步驟以下:

  (1)首先找到cxf-webservice.xml配置信息中地址,在瀏覽器中出入:http://127.0.0.1:8080/ssg?wsdl會生成文檔說明,直接給要對接的用戶便可

<jaxws:endpoint id="ssg" implementor="cn.exchange.cxf.DataExchangeWebServiceImpl"
      address="http://127.0.0.1:8080/ssg">
 </jaxws:endpoint>

  (2)使用soapUI測試接口:

  注意:在測試以前,要先開啓接口項目

  ①在接口項目開啓以後,打開工具soapUi,新建(file→create empty project),以下圖所示:

  ②右擊工程project——add wsdl,以下圖所示:

  打開以下圖的頁面:

  ③而後進入以下頁面:(修改:應該雙擊"request1")

  雙擊"request1"出現以下的窗口:

 

  ④在"?"號處輸入相關的參數,點擊運行,若是右側空白沒有出現錯誤的信息,說明接口方法可使用

  測試失敗,以下所示:(對於不一樣的項目,可能提示信息有所不一樣,要視狀況而定,這裏不是絕對的結果)

  測試成功,以下圖:(對於不一樣的項目,可能提示信息有所不一樣,要視狀況而定,這裏不是絕對的結果)

 

可見,WSDL的測試相對比較簡單,若是沒接觸過的話,花幾分鐘看下就會明白。

如上。

 

--20180912 15:49於滬 長寧白貓科技園

相關文章
相關標籤/搜索