Re: [問題] web services的問題

看板java作者 (X票已賣出 別騷擾我啦= =)時間16年前 (2009/07/08 22:51), 編輯推噓1(101)
留言2則, 2人參與, 最新討論串2/3 (看更多)
※ 引述《yzlin (自信始終來自於人心)》之銘言: : 1.要輸入的欄位 是依不同的web services會有所不同,要如何知道,我是呼叫對的web : services? 假設這只是普通的java類別? 你如何得知方法功能與需要對應的參數? 簡單來說WSDL應該有清楚描述才是 以axis2產生的ws為例 documentation標籤可以讓programer編輯敘述 : 2.當我知道要呼叫web services,要如何把值傳過去web servicesꄊ: 請各位高手,是否能幫小弟解答一下,謝謝~! SOAP這就好像WEB APP的REQUEST與RESPONSE 通常WSDL會描述她所接受的SOAP(XML)格式 只要你丟出對應的XML就會回應對應的XML 我手邊之前寫的範例 假設ws的類別為 public class hello { public String getHello(String str){ return "Hello !! "+str+",Nice to meet you."; } } 透過ws tool產生的WSDL http://127.0.0.1:8080/demo/services/hello?wsdl 取得WDSL WSDL過長 擷取重點 1. <wsdl:documentation>SAY HELLO BABY!~</wsdl:documentation> SWDL描述 2. - <xs:element name="getHello"> - <xs:complexType> - <xs:sequence> <xs:element minOccurs="0" name="str" nillable="true" type="xs:string" /> </xs:sequence> </xs:complexType> </xs:element> web service的method 當然也包括他的型別與變數名稱(str) 3. - <xs:element name="getHelloResponse"> - <xs:complexType> - <xs:sequence> <xs:element minOccurs="0" name="return" nillable="true" type="xs:string" /> </xs:sequence> </xs:complexType> </xs:element> 回應類型(string) ok開始測試web service 執行 http://127.0.0.1:8080/demo/services/hello/getHello 她就會回傳 - <ns:getHelloResponse xmlns:ns="" rel="nofollow">http://webservice.com"> <ns:return>Hello !! null,Nice to meet you.</ns:return> </ns:getHelloResponse> 如果我執行 http://127.0.0.1:8080/demo/service/hello/getHello?str=SpiderName 回傳 - <ns:getHelloResponse xmlns:ns="" rel="nofollow">http://webservice.com"> <ns:return>Hello !! SpiderName,Nice to meet you.</ns:return> </ns:getHelloResponse> 看到差異? 就是找到對應的參數囉 當然這種測試方法僅適合AXIS2的平台(因此 此方法不適用XFIRE) 補充一下 如果原PO了解Header(如Accept-Encoding、User-Agent等內容) 不懂可參考http://web-sniffer.net/ 以前我寫WEB SPIDER碰到很ㄐ的網站都要靠他... 對以上範例服務丟出 POST http://127.0.0.1:8080/demo/services/hello.helloHttpSoap11Endpoint/ HTTP/1.1 Accept-Encoding: gzip,deflate Content-Type: text/xml;charset=UTF-8 SOAPAction: "urn:getHello" User-Agent: Jakarta Commons-HttpClient/3.1 Host: 127.0.0.1:8080 Content-Length: 275 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="" rel="nofollow">http://webservice.com"> <soapenv:Header/> <soapenv:Body> <web:getHello> <web:str>SpiderName</web:str> </web:getHello> </soapenv:Body> </soapenv:Envelope> 得到的結果就是上面範例加上SOAP的TAG <soapenv:Envelope xmlns:soapenv="" rel="nofollow">http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Body> <ns:getHelloResponse xmlns:ns="" rel="nofollow">http://webservice.com"> <ns:return>Hello !! SpiderName,Nice to meet you.</ns:return> </ns:getHelloResponse> </soapenv:Body> </soapenv:Envelope> 我用結果論的展現 不知道原PO有沒有FEELING WS測試工具 如Web Service Studio 上網google一下就有啦 -- ◢█◤▏ █ ▎            ◤˙˙◥ 迷 你 邀 武 八 在 你 後 面 , 他 非 常 火 Mini158 is behind you, she is furious. -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 219.86.130.116 ※ 編輯: slalala 來自: 219.86.130.111 (07/11 12:34)

07/11 14:08, , 1F
這簽名太kuso了,改得真好.
07/11 14:08, 1F
※ 編輯: slalala 來自: 219.86.130.111 (07/11 14:17)

07/11 20:57, , 2F
這簽名很久了
07/11 20:57, 2F
文章代碼(AID): #1ALBA6HS (java)
文章代碼(AID): #1ALBA6HS (java)