作者slalala (X票已卖出 别骚扰我啦= =)
看板java
标题Re: [问题] web services的问题
时间Wed Jul 8 22:51:48 2009
※ 引述《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="
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="
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="
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="
http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns:getHelloResponse xmlns:ns="
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)
1F:推 qrtt1:这签名太kuso了,改得真好. 07/11 14:08
※ 编辑: slalala 来自: 219.86.130.111 (07/11 14:17)
2F:→ slalala:这签名很久了 07/11 20:57