Question

I'm writing an app that connect to an https web service many times using ksoap2 and the data usage of the app is high. I think it's high because I'm doing the connection every time i invoke the WS.

There is a way to use the same connection for my application like a singleton or sharing the HttpTransportSE object?

An example of my code:

public boolean Call1_Example(String Param1, String Param2)
{

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME24);
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
            SoapEnvelope.VER11);

    request.addProperty("Param1", Param1);
    request.addProperty("Param2", Param2);

    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

    Boolean resultado = false;
    Object response;

    try {


        androidHttpTransport.call(Method1_SOAP_ACTION,
                envelope);
        response = envelope.getResponse();
        resultado = Boolean.parseBoolean(response.toString());

    } catch (Exception e) {

        resultado = false;
    }

    return resultado;
}
Was it helpful?

Solution

I faced the same problem. My WS always returned the whole object I requested. So I manage that the server stores for each object its last updated time by using System.currentTimeMillis() in every setters.

When you consume your WS you retrieve the response and keep the last updated time. For the next request to the WS, you'll send this stored time.

So the server will send you only the difference. Of course, it leads to a modification of your server's code.

I don't know if it's a clean solution, but it works fine. I've got approximatively the same time response in Wifi and in 3G.

You can also use gzip to compress the message.

HeaderProperty headerProperty=new HeaderProperty("Accept-Encoding", "gzip");

You can see a sample here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top