Skip to content
Advertisement

KSoap2 on Android freezing the device instead of making a webservice call

I’m trying to connect to .NET 4.0 webservice I created for receiving SOAP-calls from Android-devices, now hosted on local IIS for testing purposes.

I found out that ksoap2 would be an excellent class library for doing what i want to do. Downloaded the .jar package from https://code.google.com/p/ksoap2-android/ and started pounding the keyboard in ecstacy… with my fingers.

The amount of information being sent is from few kilobytes to few megabytes.

What is working

HttpTransportSE.call(String, SoapSerializationEnvelope)-method works perfectly while still in Eclipse’s Android emulator, sending the call to webservice hosted in local IIS. Even tested that the webservice receives empty calls from trying to open the service address from a web browser in the same local area network.

What doesn’t work

When I copy the .apk-file to an Android device, install it, start it and trying to make the call, the whole program freezes without making the call.

As you can see from a code block presented some lines after that possible errors are being taken into account: In emulated environment a successful call returns a SoapPrimitive-object or flows into the correct catch block generating an error message for the user according to the current situation.

Then on live Android device, program loses it’s responsivity forever and has to be terminated from application menu.

What have i tried

I removed the call from the asynchronous method, and tried calling it straight from an anonymous inner function assigned for a button click-event.

Tried not trying to get a response, just making the call.

Tried getting a logcat-program for the device to see what’s happening behind the UI, found two, they needed root access, which i don’t have in the device. This is why i don’t have any logcats to show you, and showing the emulator logcat would probably(?) be useless because it works fine there.

Not trying to connect to localhost.

Tried installing the program on older Lenovo-tablet running Android 4.2.2 and on brand new Samsung Galaxy Tab, both would have the same problem while otherwise working well.

The code

Here’s the asynchronous method for making the call in device/emulator, where variables str_URL and soapRequest are a correct service address (checked) and a well formed SoapObject respectively:

@Override
protected WebServiceResult doInBackground(Void... v) {
    WebServiceResult _ret;
    SoapSerializationEnvelope soapEnvelope= new SoapSerializationEnvelope(SoapEnvelope.VER11);
    soapEnvelope.dotNet=true;
    soapEnvelope.setAddAdornments(false);
    soapEnvelope.setOutputSoapObject(soapRequest);
    HttpTransportSE conn = new HttpTransportSE(str_URL);
    conn.setXmlVersionTag("<?xml version="1.0" encoding="utf-8"?>");
    conn.debug = true;
    try {
        conn.call(str_ACTION, soapEnvelope); 
        SoapObject o = (SoapObject)soapEnvelope.getResponse();
        _ret = new WebServiceResult(o, WebServiceResultEnum.ok);
    } catch (NetworkOnMainThreadException e) {
        _ret = new WebServiceResult(null, WebServiceResultEnum.keskeytys);
    } catch (HttpResponseException e) {
        _ret = new WebServiceResult(null, WebServiceResultEnum.httpVirhe);
    } catch (XmlPullParserException e) {
        _ret = new WebServiceResult(null, WebServiceResultEnum.vaara_muoto);
    } catch (SocketTimeoutException e) {
        _ret = new WebServiceResult(null, WebServiceResultEnum.aikakatkaisu);
    } catch (Exception e) {
        _ret = new WebServiceResult(null, WebServiceResultEnum.keskeytys);
    }
    return _ret;
}

Thank you in advance!

Advertisement

Answer

It seems that I had declared the minimum SDK as 14 and target SDK as 17 in AndroidManifest.xml. I didn’t use any fancy things in newer sdk’s so i lowered the target SDK to the same level as minimum SDK, 14. I also had an Avast! Antivirus service running on the tablet which i removed.

This solved my problem. It could be that probably the Avast! antivirus-program wanted to block all communications from applications not downloaded from Play-store. I don’t know if changing the target SDK had much effect really.

5 People found this is helpful
Advertisement