XmlPullParserException:使用KSOAP2库的Android应用程序中的意外类型(位置:END_DOCUMENT null @ 1:1 in java.io.InputStreamReader)

时间:2016-06-03 20:41:28

标签: java xml web-services ksoap2

这是我在这里的第一个问题,我一直在寻找解决方案,但我发现的所有相似的情况或问题都没有答案。所以我用android进行了一个简单的测试,它使用了一个提供以下主体的本地Web服务:

<?xml version="1.0" encoding="UTF-8"?>

-<wsdl:definitions xmlns:soapenc12="http://www.w3.org/2003/05/soap-encoding" xmlns:soap11="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope" xmlns:tns="http://xfire.codehaus.org/Calculadora" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soapenc11="http://schemas.xmlsoap.org/soap/encoding/" targetNamespace="http://xfire.codehaus.org/Calculadora">


-<wsdl:types>


-<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://xfire.codehaus.org/Calculadora" elementFormDefault="qualified" attributeFormDefault="qualified">


-<xsd:element name="mult">


-<xsd:complexType>


-<xsd:sequence>

<xsd:element name="in0" type="xsd:int" minOccurs="1" maxOccurs="1"/>

<xsd:element name="in1" type="xsd:int" minOccurs="1" maxOccurs="1"/>

</xsd:sequence>

</xsd:complexType>

</xsd:element>


-<xsd:element name="multResponse">


-<xsd:complexType>


-<xsd:sequence>

<xsd:element name="out" type="xsd:int" minOccurs="1" maxOccurs="1"/>

</xsd:sequence>

</xsd:complexType>

</xsd:element>


-<xsd:element name="soma">


-<xsd:complexType>


-<xsd:sequence>

<xsd:element name="in0" type="xsd:int" minOccurs="1" maxOccurs="1"/>

<xsd:element name="in1" type="xsd:int" minOccurs="1" maxOccurs="1"/>

</xsd:sequence>

</xsd:complexType>

</xsd:element>


-<xsd:element name="somaResponse">


-<xsd:complexType>


-<xsd:sequence>

<xsd:element name="out" type="xsd:int" minOccurs="1" maxOccurs="1"/>

</xsd:sequence>

</xsd:complexType>

</xsd:element>


-<xsd:element name="hello">

<xsd:complexType/>

</xsd:element>


-<xsd:element name="helloResponse">


-<xsd:complexType>


-<xsd:sequence>

<xsd:element name="out" type="xsd:string" minOccurs="1" maxOccurs="1" nillable="true"/>

</xsd:sequence>

</xsd:complexType>

</xsd:element>

</xsd:schema>

</wsdl:types>


-<wsdl:message name="helloResponse">

<wsdl:part name="parameters" element="tns:helloResponse"> </wsdl:part>

</wsdl:message>


-<wsdl:message name="helloRequest">

<wsdl:part name="parameters" element="tns:hello"> </wsdl:part>

</wsdl:message>


-<wsdl:message name="multRequest">

<wsdl:part name="parameters" element="tns:mult"> </wsdl:part>

</wsdl:message>


-<wsdl:message name="somaRequest">

<wsdl:part name="parameters" element="tns:soma"> </wsdl:part>

</wsdl:message>


-<wsdl:message name="multResponse">

<wsdl:part name="parameters" element="tns:multResponse"> </wsdl:part>

</wsdl:message>


-<wsdl:message name="somaResponse">

<wsdl:part name="parameters" element="tns:somaResponse"> </wsdl:part>

</wsdl:message>


-<wsdl:portType name="CalculadoraPortType">


-<wsdl:operation name="mult">

<wsdl:input name="multRequest" message="tns:multRequest"> </wsdl:input>

<wsdl:output name="multResponse" message="tns:multResponse"> </wsdl:output>

</wsdl:operation>


-<wsdl:operation name="soma">

<wsdl:input name="somaRequest" message="tns:somaRequest"> </wsdl:input>

<wsdl:output name="somaResponse" message="tns:somaResponse"> </wsdl:output>

</wsdl:operation>


-<wsdl:operation name="hello">

<wsdl:input name="helloRequest" message="tns:helloRequest"> </wsdl:input>

<wsdl:output name="helloResponse" message="tns:helloResponse"> </wsdl:output>

</wsdl:operation>

</wsdl:portType>


-<wsdl:binding name="CalculadoraHttpBinding" type="tns:CalculadoraPortType">

<wsdlsoap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>


-<wsdl:operation name="mult">

<wsdlsoap:operation soapAction=""/>


-<wsdl:input name="multRequest">

<wsdlsoap:body use="literal"/>

</wsdl:input>


-<wsdl:output name="multResponse">

<wsdlsoap:body use="literal"/>

</wsdl:output>

</wsdl:operation>


-<wsdl:operation name="soma">

<wsdlsoap:operation soapAction=""/>


-<wsdl:input name="somaRequest">

<wsdlsoap:body use="literal"/>

</wsdl:input>


-<wsdl:output name="somaResponse">

<wsdlsoap:body use="literal"/>

</wsdl:output>

</wsdl:operation>


-<wsdl:operation name="hello">

<wsdlsoap:operation soapAction=""/>


-<wsdl:input name="helloRequest">

<wsdlsoap:body use="literal"/>

</wsdl:input>


-<wsdl:output name="helloResponse">

<wsdlsoap:body use="literal"/>

</wsdl:output>

</wsdl:operation>

</wsdl:binding>


-<wsdl:service name="Calculadora">


-<wsdl:port name="CalculadoraHttpPort" binding="tns:CalculadoraHttpBinding">

<wsdlsoap:address location="http://localhost:8080/livro_android_xfire/services/Calculadora"/>

</wsdl:port>

</wsdl:service>

</wsdl:definitions>

客户端是一个Android应用程序,代码如下:

String url = "http://XX.X.X.X:8080/livro_android_xfire/services/Calculadora?wsdl"

SoapObject soap = new SoapObject("urn:Calculadora", "soma");

// Adiciona os parâmetros para a soma
soap.addProperty("n1", n1);
soap.addProperty("n2", n2);

// Cria o envelope com o objeto SOAP
SoapSerializationEnvelope envelope = new   SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(soap);

Log.i(TAG, "Calling WebService: " + url);

// Cria o HttpTransport para enviar os dados (SOAP)
HttpTransportSE httpTransport = new LivroHttpTransport(url);
httpTransport.debug = true;

// Faz a requisição
httpTransport.call("", envelope);

我已关注httpTransport.call并注意到当它到达this.parseResponse(envelope, (InputStream)is);类中的方法HttpTransportSE时,它会抛出异常 org.xmlpull.v1.XmlPullParserException: unexpected type (position:END_DOCUMENT null@1:1 in java.io.InputStreamReader@286e958)

有人可以帮我吗?

1 个答案:

答案 0 :(得分:0)

大家好,感谢您的注意,但是,我解决了这个问题,并且我确实错了,网址不对,“http://XX.X.X.X:8080/livro_android_xfire/services/Calculadora?wsdl”应该是“http://XX.X.X.X:8080/livro_android_xfire/services/Calculadora”。现在正在运行。 Thaks