Connecting to Web Service with KSOAP2 - getting XmlPullParserException
I saw some other users with the same problem but honestly the answers didnt helped me.
I have a android client which connects to a PHP Web Service (using NuSOAP), and locally everything works fine. When I deployed my webservice and updated the variables on the client, I'm getting the following error:
org.xmlpull.v1.xmlpullparserexception: unexpected type (position: END_DOCUMENT null@1:0 in java.io.InputStreamReader@44f11f30)
This happens randomly - for example, for login, if the first try is "wrong password" (sucessfull connection to the web service) the second try I get that error. If it's accepted I got a force close of the application (i start another activity) I suppose it's because of that problem.
I have no idea what's the problem much because I don't handle any XML file manually and my WDSL is fine as you can see here
My connect strings are the following:
private static final String URL = "http://apkitchen.voku-online.de:8080/webs.php";
private static final String NAMESPACE = "urn:hellowsdl";
final String SOAP_ACTION = "urn:hellowsdl#auth";
final String METHOD_NAME = "auth";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
My full connecting function is:
public Object soap(String METHOD_NAME, String SOAP_ACTION, String NAMESPACE, String URL)
throws IOException, XmlPullParserException {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("username", "Maxxd");
request.addProperty("password", "xxxx");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(URL);
httpTransport.call(SOAP_ACTION, envelope);
Object result = envelope.getResponse();
return result;
}
I honestly have no idea why this happens.... any help?
FOUND THE PROBLEM (BUT NOT THE SOLUTION...)
I dumped the response xml file, and looks like it's mall formed:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:authResponse xmlns:ns1="urn:hellowsdl">
<return xsi:type="xsd:string">0</return>
</ns1:开发者_StackOverflowauthResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
<!..................
The envelope itself it's ok, but there is not ending comment tag... how can I solve this ?
Looks like it's an issue on KSOAP2 android implementation on api level < 9.
It's solved using
System.setProperty("http.keepAlive", "false");
I hope this hopes someone, because I saw dozens of people with the same problem.
I'm not sure if it would help you but I had the same exception. When I changed the Envelope version from 11 to 10, it magically gone :o. Maybe you might want to give it a try.
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER10);
精彩评论