簡體   English   中英

XmlPullParserException:expected:START_TAG <... definitions

[英]XmlPullParserException: expected: START_TAG <…definitions

這是我為php (Yii)web服務調用連接到android創建的WSDL 但我明白了

10-19 11:17:36.068: W/System.err(11165): org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG <{http://schemas.xmlsoap.org/wsdl/}wsdl:definitions name='StatisticController' targetNamespace='http://example.com/webservice/statistic/'>@13:91 in java.io.InputStreamReader@40539de0) 

XML:

<wsdl:definitions name="StatisticController" targetNamespace="http://example.com/webservice/statistic/">
  <wsdl:message name="getGeneralstatRequest"/>
  <wsdl:message name="getGeneralstatResponse">
     <wsdl:part name="return" type="xsd:struct"/>
  </wsdl:message>
  <wsdl:portType name="StatisticControllerPortType">
     <wsdl:operation name="getGeneralstat">
       <wsdl:documentation/>
       <wsdl:input message="tns:getGeneralstatRequest"/>
       <wsdl:output message="tns:getGeneralstatResponse"/>
     </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="StatisticControllerBinding" type="tns:StatisticControllerPortType">
     <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
     <wsdl:operation name="getGeneralstat">
        <soap:operation soapAction="http://example.com/webservice/statistic/getGeneralstat" style="rpc"/>
        <wsdl:input>
           <soap:body use="encoded" namespace="http://example.com/webservice/statistic/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
        </wsdl:input>
        <wsdl:output>
           <soap:body use="encoded" namespace="http://example.com/webservice/statistic/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
        </wsdl:output>
     </wsdl:operation>
   </wsdl:binding>
   <wsdl:service name="StatisticControllerService">
      <wsdl:port name="StatisticControllerPort" binding="tns:StatisticControllerBinding">
          <soap:address location="http://example.com/webservice/statistic/ws/1"/>
      </wsdl:port>
   </wsdl:service>

Webservice正在工作。 我測試了http://www.validwsdl.com/

Java代碼:

    private static String domain_name = URLEncoder.encode("example.com");
    private static final String METHOD_NAME = "getGeneralstat";
    private static final String NAMESPACE = "http://"+ domain_name +"/webservice/statistic/";
    //private static final String URL = "http://"+ domain_name +"/webservice/statistic/";
    private static final String URL = "http://"+ domain_name +"/webservice/generalstat2.wsdl";
   private static final String SOAP_ACTION = NAMESPACE + METHOD_NAME;
...
   SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
   SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
   envelope.setOutputSoapObject(request);
   HttpTransportSE ht = new HttpTransportSE(URL,8000); // trying 8 sec  
   try {    
     ht.debug = true;
     ht.call(SOAP_ACTION, envelope);
...
   } catch ...
   } catch ...
   } catch (XmlPullParserException xe) {
   } catch ...

我已經嘗試了3個星期,但它沒有用。 我已經閱讀了很多主題,但沒有解決我的問題。

XMLParserException可能會在兩點拋出。

  1. 當庫嘗試在調用之前生成SoapObject時
  2. 在調用之后,當響應對象不是有效的XML時(例如,您可以獲得)
    帶有服務器錯誤的HTML響應)

調試Webservice調用並檢查HTTPTransportSE對象的轉儲變量,以確定您的XML是否有效。 您還可以將轉儲變量的內容復制粘貼到soapUI中,以檢查哪些xml部分不起作用。

這幫助了我很多http://mspmsp.brinkster.net/MobileJava/ch16.htm

我希望它有所幫助。

你給定的wsdl絕對不正確:有一些命名空間聲明缺失加上wsdl:definitions標簽未在文件末尾正確關閉(可能是復制+粘貼錯誤)。 這是一個更正版本:

<wsdl:definitions name="StatisticController" 
targetNamespace="http://example.com/webservice/statistic/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://example.com/webservice/statistic/">
  <wsdl:message name="getGeneralstatRequest"/>
  <wsdl:message name="getGeneralstatResponse">
     <wsdl:part name="return" type="xsd:struct"/>
  </wsdl:message>
  <wsdl:portType name="StatisticControllerPortType">
     <wsdl:operation name="getGeneralstat">
       <wsdl:documentation/>
       <wsdl:input message="tns:getGeneralstatRequest"/>
       <wsdl:output message="tns:getGeneralstatResponse"/>
     </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="StatisticControllerBinding" type="tns:StatisticControllerPortType">
     <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
     <wsdl:operation name="getGeneralstat">
        <soap:operation soapAction="http://example.com/webservice/statistic/getGeneralstat" style="rpc"/>
        <wsdl:input>
           <soap:body use="encoded" namespace="http://example.com/webservice/statistic/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
        </wsdl:input>
        <wsdl:output>
           <soap:body use="encoded" namespace="http://example.com/webservice/statistic/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
        </wsdl:output>
     </wsdl:operation>
   </wsdl:binding>
   <wsdl:service name="StatisticControllerService">
      <wsdl:port name="StatisticControllerPort" binding="tns:StatisticControllerBinding">
          <soap:address location="http://example.com/webservice/statistic/ws/1"/>
      </wsdl:port>
   </wsdl:service>
</wsdl:definitions>

我建議將WSDL導入soapUI,作為一個快速簡單的驗證步驟。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM