首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >XmlPullParserException:预期: START_TAG <...definitions

XmlPullParserException:预期: START_TAG <...definitions
EN

Stack Overflow用户
提问于 2012-10-19 18:20:21
回答 2查看 4.5K关注 0票数 3

这是我为php (Yii)网络服务调用创建的用于连接到android的WSDL。但我得到了

代码语言:javascript
复制
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:

代码语言:javascript
复制
<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代码:

代码语言:javascript
复制
    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个星期了,但是没有效果。我读了很多很多的主题,但都没有解决我的问题。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-10-19 18:54:46

XMLParserException可能会在两个点被抛出。

  1. 当库在调用之前尝试生成SoapObject时
  2. 调用之后,当响应对象不是有效的XML时(例如,您可以获取

带有服务器错误的超文本标记语言响应)

调试您的Webservice调用并检查HTTPTransportSE对象的转储变量,以确定您的XML是否有效。您还可以将转储变量的内容复制粘贴到soapUI中,以检查哪些xml不工作。

这帮助了我很多http://mspmsp.brinkster.net/MobileJava/ch16.htm

我希望它能帮上忙。

票数 1
EN

Stack Overflow用户

发布于 2012-10-22 20:05:00

您给定的wsdl肯定是不正确的:缺少一些名称空间声明,而且wsdl:definitions标记在文件末尾没有正确结束(可能是copy+paste错误)。这是一个更正的版本:

代码语言:javascript
复制
<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中,作为一种快速而简单的验证步骤。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12972212

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档