如何饮用此WebService在Android中? [英] How to consume this WebService in Android?
问题描述
我开发一个应用程序使用的Web服务,如何消费以下Web服务? HTTP方法或ksoap2?我试过Ksoap2,似乎不能正确地提取该Web服务,任何人都可以帮助这个吗?先谢谢了。
下面是WSDL: http://www.restfulwebservices.net/wcf/StockQuoteService .SVC?WSDL
时的NAME_SPACE是: http://www.restfulwebservices.net/ServiceContracts/2008/ 01 ?方法是GetStockQuote?而SOAP_ACTION是GetStockQuote?
<?XML版本=1.0编码=UTF-8&GT?;
< WSDL:定义名称=的StockQuoteService
的targetNamespace =http://www.restfulwebservices.net/ServiceContracts/2008/01
的xmlns:WSDL =http://schemas.xmlsoap.org/wsdl/
的xmlns:SOAP =http://schemas.xmlsoap.org/wsdl/soap/
的xmlns:WSU =http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd
的xmlns:SOAPENC =http://schemas.xmlsoap.org/soap/encoding/
的xmlns:WSAM =http://www.w3.org/2007/05/addressing/metadata
的xmlns:TNS =http://www.restfulwebservices.net/ServiceContracts/2008/01
的xmlns:WSA =http://schemas.xmlsoap.org/ws/2004/08/addressing
的xmlns:WSP =http://schemas.xmlsoap.org/ws/2004/09/policy
的xmlns:WSAP =http://schemas.xmlsoap.org/ws/2004/08/addressing/policy
的xmlns:XSD =http://www.w3.org/2001/XMLSchema
的xmlns:MSC =http://schemas.microsoft.com/ws/2005/12/wsdl/contract
的xmlns:WSAW =http://www.w3.org/2006/05/addressing/wsdl
的xmlns:SOAP12 =http://schemas.xmlsoap.org/wsdl/soap12/
的xmlns:wsa10 =http://www.w3.org/2005/08/addressing
的xmlns:WSX =http://schemas.xmlsoap.org/ws/2004/09/mex>
< WSDL:类型>
< XSD:架构的targetNamespace =http://www.restfulwebservices.net/ServiceContracts/2008/01/Imports> < XSD:导入的schemaLocation =http://www.restfulwebservices.net/wcf/StockQuoteService.svc?xsd=xsd0
命名空间=http://www.restfulwebservices.net/ServiceContracts/2008/01/>
< XSD:导入的schemaLocation =http://www.restfulwebservices.net/wcf/StockQuoteService.svc?xsd=xsd3
命名空间=HTTP://GOTLServices.FaultContracts/2008/01/>
< XSD:导入的schemaLocation =http://www.restfulwebservices.net/wcf/StockQuoteService.svc?xsd=xsd1
命名空间=http://schemas.microsoft.com/2003/10/Serialization//>
< XSD:导入的schemaLocation =http://www.restfulwebservices.net/wcf/StockQuoteService.svc?xsd=xsd2
命名空间=http://www.restfulwebservices.net/DataContracts/2008/01/>
< / XSD:架构>
< / WSDL:类型>
< WSDL:消息名称=IStockQuoteService_GetStockQuote_InputMessage> < WSDL:部分名称=参数元素=TNS:GetStockQuote/>
< / WSDL:消息>
< WSDL:消息名称=IStockQuoteService_GetStockQuote_OutputMessage> < WSDL:部分名称=参数
元素=TNS:GetStockQuoteResponse/>
< / WSDL:消息>
< WSDL:消息名称=IStockQuoteService_GetStockQuote_DefaultFaultContractFault_FaultMessage> < WSDL:部分名称=细节元素=Q1:DefaultFaultContract
的xmlns:Q1 =HTTP://GOTLServices.FaultContracts/2008/01/>
< / WSDL:消息>
< WSDL:消息名称=IStockQuoteService_GetWorldMajorIndices_InputMessage> < WSDL:部分名称=参数
元素=TNS:GetWorldMajorIndices/>
< / WSDL:消息>
< WSDL:消息名称=IStockQuoteService_GetWorldMajorIndices_OutputMessage> < WSDL:部分名称=参数
元素=TNS:GetWorldMajorIndicesResponse/>
< / WSDL:消息>
< WSDL:消息名称=IStockQuoteService_GetWorldMajorIndices_DefaultFaultContractFault_FaultMessage> < WSDL:部分名称=细节元素=Q2:DefaultFaultContract
的xmlns:Q2 =HTTP://GOTLServices.FaultContracts/2008/01/>
< / WSDL:消息>
< WSDL:portType的名称=IStockQuoteService>
< WSDL:操作名称=GetStockQuote>
< WSDL:输入WSAW:行动=GetStockQuote
消息=TNS:IStockQuoteService_GetStockQuote_InputMessage/>
< WSDL:输出wsaw:Action=\"http://www.restfulwebservices.net/ServiceContracts/2008/01/IStockQuoteService/GetStockQuoteResponse\"
消息=TNS:IStockQuoteService_GetStockQuote_OutputMessage/>
< WSDL:故障wsaw:Action=\"http://www.restfulwebservices.net/ServiceContracts/2008/01/IStockQuoteService/GetStockQuoteDefaultFaultContractFault\"
NAME =DefaultFaultContractFault
消息=TNS:IStockQuoteService_GetStockQuote_DefaultFaultContractFault_FaultMessage/>
< / WSDL:运转>
< WSDL:操作名称=GetWorldMajorIndices>
< WSDL:输入WSAW:行动=GetWorldMajorIndices
消息=TNS:IStockQuoteService_GetWorldMajorIndices_InputMessage/>
< WSDL:输出wsaw:Action=\"http://www.restfulwebservices.net/ServiceContracts/2008/01/IStockQuoteService/GetWorldMajorIndicesResponse\"
消息=TNS:IStockQuoteService_GetWorldMajorIndices_OutputMessage/>
< WSDL:故障wsaw:Action=\"http://www.restfulwebservices.net/ServiceContracts/2008/01/IStockQuoteService/GetWorldMajorIndicesDefaultFaultContractFault\"
NAME =DefaultFaultContractFault
消息=TNS:IStockQuoteService_GetWorldMajorIndices_DefaultFaultContractFault_FaultMessage/>
< / WSDL:运转>
< / WSDL:portType的>
< WSDL:绑定名称=BasicHttpBinding_IStockQuoteService
键入=TNS:IStockQuoteService>
<肥皂:绑定传输=http://schemas.xmlsoap.org/soap/http/>
< WSDL:操作名称=GetStockQuote>
<肥皂:操作的soapAction =GetStockQuote
风格=文件/>
< WSDL:输入>
<肥皂:身体使用=文字/>
< / WSDL:输入>
< WSDL:输出>
<肥皂:身体使用=文字/>
< / WSDL:输出>
< WSDL:故障名称=DefaultFaultContractFault>
<肥皂:故障名称=DefaultFaultContractFault
使用=文字/>
< / WSDL:故障>
< / WSDL:运转>
< WSDL:操作名称=GetWorldMajorIndices>
<肥皂:操作的soapAction =GetWorldMajorIndices
风格=文件/>
< WSDL:输入>
<肥皂:身体使用=文字/>
< / WSDL:输入>
< WSDL:输出>
<肥皂:身体使用=文字/>
< / WSDL:输出>
< WSDL:故障名称=DefaultFaultContractFault>
<肥皂:故障名称=DefaultFaultContractFault
使用=文字/>
< / WSDL:故障>
< / WSDL:运转>
< / WSDL:结合>
< WSDL:服务名称=的StockQuoteService>
< WSDL:端口名称=BasicHttpBinding_IStockQuoteService
绑定=TNS:BasicHttpBinding_IStockQuoteService>
<肥皂:地址位置=http://www.restfulwebservices.net/wcf/StockQuoteService.svc/>
< / WSDL:端口>
< / WSDL:服务>
< / WSDL:定义>
下面是requestDump:
<五:信封的xmlns:I =http://www.w3.org/2001/XMLSchema-instance
的xmlns:D =http://www.w3.org/2001/XMLSchema
的xmlns:C =http://schemas.xmlsoap.org/soap/encoding/
的xmlns:V =http://schemas.xmlsoap.org/soap/envelope/>
<五:页眉/>
<五:身体与GT;
< GetStockQuote的xmlns =http://www.restfulwebservices.net/ServiceContracts/2008/01
ID =O0C:根=1>
<参数I:TYPE =D:字符串> IBM< /参数>
< / GetStockQuote>
< / V:车身>
< / V:信封>
responseDump:
< S:信封的xmlns:S =http://schemas.xmlsoap.org/soap/envelope/>
< S:身体与GT;
< S:故障>
<故障code的xmlns:A =http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher>
答:InternalServiceFault< /故障code>
< faultstring XML:LANG =EN-US>对象引用不设置到
实例对象的&所述; / faultstring>
<详情>
< ExceptionDetail的xmlns =http://schemas.datacontract.org/2004/07/System.ServiceModel
的xmlns:I =http://www.w3.org/2001/XMLSchema-instance>
< HELPLINK我:无=真/>
<我的InnerException:无=真/>
<消息>未将对象引用设置的一个实例
对象< /信息>
<&栈跟踪GT;在
GOTLServices.ServiceImplementation.StockQuoteService.GetStockQuote(字符串
符号)
< /堆栈跟踪>
< / ExceptionDetail>
< /详情>
< / S:故障>
< / S:身体与GT;
< / S:信封>
阅读来自谟维基链接以及常见问题(特别是对如何调试项目),看看是否你有一个适当的请求和responsedump。
HTTP://$c$c.google.com/p/ksoap2 -Android /
HTTP://$c$c.google.com/ p / ksoap2-的Android /维基/链接
HTTP://$c$c.google.com/ p / ksoap2-的Android /维基/ CodingTipsAndTricks
和还考虑要求该项目的邮件列表上。
I am developing a application to consume the web service, how to consume the following web-service? http method or ksoap2? I tried Ksoap2, seems can not extract this web service properly, anybody can help on this? thanks in advance.
Here is the wsdl: http://www.restfulwebservices.net/wcf/StockQuoteService.svc?wsdl
Is that the NAME_SPACE is: http://www.restfulwebservices.net/ServiceContracts/2008/01? method is GetStockQuote? and the SOAP_ACTION is GetStockQuote?
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions name="StockQuoteService"
targetNamespace="http://www.restfulwebservices.net/ServiceContracts/2008/01"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata"
xmlns:tns="http://www.restfulwebservices.net/ServiceContracts/2008/01"
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract"
xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:wsa10="http://www.w3.org/2005/08/addressing"
xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex">
<wsdl:types>
<xsd:schema targetNamespace="http://www.restfulwebservices.net/ServiceContracts/2008/01/Imports">
<xsd:import schemaLocation="http://www.restfulwebservices.net/wcf/StockQuoteService.svc?xsd=xsd0"
namespace="http://www.restfulwebservices.net/ServiceContracts/2008/01" />
<xsd:import schemaLocation="http://www.restfulwebservices.net/wcf/StockQuoteService.svc?xsd=xsd3"
namespace="http://GOTLServices.FaultContracts/2008/01" />
<xsd:import schemaLocation="http://www.restfulwebservices.net/wcf/StockQuoteService.svc?xsd=xsd1"
namespace="http://schemas.microsoft.com/2003/10/Serialization/" />
<xsd:import schemaLocation="http://www.restfulwebservices.net/wcf/StockQuoteService.svc?xsd=xsd2"
namespace="http://www.restfulwebservices.net/DataContracts/2008/01" />
</xsd:schema>
</wsdl:types>
<wsdl:message name="IStockQuoteService_GetStockQuote_InputMessage">
<wsdl:part name="parameters" element="tns:GetStockQuote" />
</wsdl:message>
<wsdl:message name="IStockQuoteService_GetStockQuote_OutputMessage">
<wsdl:part name="parameters"
element="tns:GetStockQuoteResponse" />
</wsdl:message>
<wsdl:message name="IStockQuoteService_GetStockQuote_DefaultFaultContractFault_FaultMessage">
<wsdl:part name="detail" element="q1:DefaultFaultContract"
xmlns:q1="http://GOTLServices.FaultContracts/2008/01" />
</wsdl:message>
<wsdl:message name="IStockQuoteService_GetWorldMajorIndices_InputMessage">
<wsdl:part name="parameters"
element="tns:GetWorldMajorIndices" />
</wsdl:message>
<wsdl:message name="IStockQuoteService_GetWorldMajorIndices_OutputMessage">
<wsdl:part name="parameters"
element="tns:GetWorldMajorIndicesResponse" />
</wsdl:message>
<wsdl:message name="IStockQuoteService_GetWorldMajorIndices_DefaultFaultContractFault_FaultMessage">
<wsdl:part name="detail" element="q2:DefaultFaultContract"
xmlns:q2="http://GOTLServices.FaultContracts/2008/01" />
</wsdl:message>
<wsdl:portType name="IStockQuoteService">
<wsdl:operation name="GetStockQuote">
<wsdl:input wsaw:Action="GetStockQuote"
message="tns:IStockQuoteService_GetStockQuote_InputMessage" />
<wsdl:output wsaw:Action="http://www.restfulwebservices.net/ServiceContracts/2008/01/IStockQuoteService/GetStockQuoteResponse"
message="tns:IStockQuoteService_GetStockQuote_OutputMessage" />
<wsdl:fault wsaw:Action="http://www.restfulwebservices.net/ServiceContracts/2008/01/IStockQuoteService/GetStockQuoteDefaultFaultContractFault"
name="DefaultFaultContractFault"
message="tns:IStockQuoteService_GetStockQuote_DefaultFaultContractFault_FaultMessage" />
</wsdl:operation>
<wsdl:operation name="GetWorldMajorIndices">
<wsdl:input wsaw:Action="GetWorldMajorIndices"
message="tns:IStockQuoteService_GetWorldMajorIndices_InputMessage" />
<wsdl:output wsaw:Action="http://www.restfulwebservices.net/ServiceContracts/2008/01/IStockQuoteService/GetWorldMajorIndicesResponse"
message="tns:IStockQuoteService_GetWorldMajorIndices_OutputMessage" />
<wsdl:fault wsaw:Action="http://www.restfulwebservices.net/ServiceContracts/2008/01/IStockQuoteService/GetWorldMajorIndicesDefaultFaultContractFault"
name="DefaultFaultContractFault"
message="tns:IStockQuoteService_GetWorldMajorIndices_DefaultFaultContractFault_FaultMessage" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="BasicHttpBinding_IStockQuoteService"
type="tns:IStockQuoteService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="GetStockQuote">
<soap:operation soapAction="GetStockQuote"
style="document" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
<wsdl:fault name="DefaultFaultContractFault">
<soap:fault name="DefaultFaultContractFault"
use="literal" />
</wsdl:fault>
</wsdl:operation>
<wsdl:operation name="GetWorldMajorIndices">
<soap:operation soapAction="GetWorldMajorIndices"
style="document" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
<wsdl:fault name="DefaultFaultContractFault">
<soap:fault name="DefaultFaultContractFault"
use="literal" />
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="StockQuoteService">
<wsdl:port name="BasicHttpBinding_IStockQuoteService"
binding="tns:BasicHttpBinding_IStockQuoteService">
<soap:address location="http://www.restfulwebservices.net/wcf/StockQuoteService.svc" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
Here is the requestDump:
<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
xmlns:d="http://www.w3.org/2001/XMLSchema"
xmlns:c="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
<v:Header />
<v:Body>
<GetStockQuote xmlns="http://www.restfulwebservices.net/ServiceContracts/2008/01"
id="o0" c:root="1">
<parameters i:type="d:string">IBM</parameters>
</GetStockQuote>
</v:Body>
</v:Envelope>
responseDump:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<s:Fault>
<faultcode xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">
a:InternalServiceFault</faultcode>
<faultstring xml:lang="en-US">Object reference not set to an
instance of an object.</faultstring>
<detail>
<ExceptionDetail xmlns="http://schemas.datacontract.org/2004/07/System.ServiceModel"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<HelpLink i:nil="true" />
<InnerException i:nil="true" />
<Message>Object reference not set to an instance of an
object.</Message>
<StackTrace>at
GOTLServices.ServiceImplementation.StockQuoteService.GetStockQuote(String
symbol)
</StackTrace>
</ExceptionDetail>
</detail>
</s:Fault>
</s:Body>
</s:Envelope>
Read the links on the projet wiki as well as the FAQ (especially on how to debug the project) and see if that you have a proper request and responsedump.
http://code.google.com/p/ksoap2-android/
http://code.google.com/p/ksoap2-android/wiki/Links
http://code.google.com/p/ksoap2-android/wiki/CodingTipsAndTricks
and also consider asking on the project mailing list.
这篇关于如何饮用此WebService在Android中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!