Android中如何使用这个WebService呢?

发布于 2024-11-07 07:07:33 字数 8609 浏览 3 评论 0原文

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

这是请求转储:

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

响应转储:

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

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏九 2024-11-14 07:07:33

阅读 projet wiki 上的链接以及常见问题解答(尤其是如何调试项目),看看您是否有正确的请求和响应转储。

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文