1. 程式人生 > >WSDL測試webservice接口記錄

WSDL測試webservice接口記錄

config ipad detail line asmx xmlns 教程 一次 too

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

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

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

請求:

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格式化結果:

{
"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"
}

技術分享圖片

其他

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

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於滬 長寧白貓科技園

WSDL測試webservice接口記錄