如何在Android中使用此WebService?

时间:2011-05-16 07:59:24

标签: android web-services ksoap2

我正在开发一个使用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 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>

这是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>

1 个答案:

答案 0 :(得分:0)

阅读projet wiki上的链接以及FAQ(特别是如何调试项目),看看你是否有正确的请求和响应转储。

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

并考虑询问项目邮件列表。