Search code examples
androidandroid-ksoap2xmlpullparser

SOAP call throwing XMLPullParser Exception only in real device


I'm using KSOAP2 library in my Android app to call a SOAP service. The code works fine in emulator with version 2.2. But when i try to run the app in my phone(HTC Wildfire) which is also 2.2, I'm getting XMLPullParser Exception... Saw this link but no one has replied to that.Also, saw another discussion here but didn't understand exactly what was being suggested there. Can someone give me any idea as in how to solve this issue? Or is there any other reliable ways to consume a SOAP service which I can use? Please find below my code and the logs.

SoapObject request=new SoapObject(NAMESPACE, METHOD_NAME);
            SoapSerializationEnvelope envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.dotNet=true;
            envelope.setOutputSoapObject(request);
            envelope.setOutputSoapObject(request);
            envelope.implicitTypes = false;


            HttpTransportSE transport=new HttpTransportSE(URL);

            try{
                Log.v("Inside","Inside try");
                transport.debug = true;
                transport.call(SOAP_ACTION, envelope);

                String xml=transport.responseDump;
                XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
                 factory.setNamespaceAware(true);
                 XmlPullParser xpp = factory.newPullParser();

                 xpp.setInput( new StringReader ( xml ) );
                 int eventType = xpp.getEventType();
                 while (eventType != XmlPullParser.END_DOCUMENT) {
                  if(eventType == XmlPullParser.START_DOCUMENT) {
                      System.out.println("Start document");
                  } else if(eventType == XmlPullParser.START_TAG) {
                      if(xpp.getName().equals("MMDraw")){
                          System.out.println("Start tag "+xpp.getName());
                          megaMResult=new HashMap<String, String>();
                          boolean endParse=false;
                          while(!endParse){
                                          xpp.nextTag();
                              if(xpp.getEventType()==XmlPullParser.END_TAG && xpp.getName().equals("MMDraw") )
                              {
                                   endParse=true;
                                   System.out.println("End Tag of MMDraw Reached");
                              }
                              else{
                                  String key=xpp.getName();
                                  megaMResult.put(xpp.getName(), xpp.nextText());

                              }
                          }

Messages from the Log while running on the real device

05-11 00:00:19.413: W/System.err(8531): org.xmlpull.v1.XmlPullParserException: unexpected type (position:END_DOCUMENT null@1:0 in java.io.InputStreamReader@44830068) 

Solution

  • Your xml is written correctly? this erro is a parser exception, try read your xml on a soapUI program before.