3

这是WSDL我为php(Yii) Web 服务调用创建的以连接到 android。但我明白了

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>

网络服务正在工作。我用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 周,但它不起作用。我已经阅读了很多主题,但没有解决我的问题。

4

2 回答 2

1

XMLParserException 可能会在两点被抛出。

  1. 当库尝试在调用之前生成 SoapObject 时
  2. 调用后,当响应对象不是有效的 XML 时(例如,您可能会收到
    带有服务器错误的 HTML 响应)

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

这对我帮助很大http://mspmsp.brinkster.net/MobileJava/ch16.htm

我希望它有所帮助。

于 2012-10-19T10:54:45.510 回答
0

您给定的 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 中作为快速简单的验证步骤。

于 2012-10-22T12:04:59.827 回答