0

I have developed software that uses the ksoap library and communicates with a .NET web service.

all works fine and fast in the android 2.2 version.

Recently, I was forced to move to the 2.3.3 Android version.

i just changed in the project properties to 2.3.3 and compile.

there is some bugs but the one who Worries me the most is that the communication with the web service is really really slow...

I'm using ksoap 2.5.7 version...

and idea??

thanks in advance!

My Make Request function:

public void MakeRequest(final String MethodName,
        final PropertyInfo[] props, final ResponseListener resListener,
        final int timeout, final int retries)
{

    GeneralMethods.debug(this.getClass().toString(), "MakeRequest",
            "MethodName=" + MethodName);
    for (PropertyInfo prop : props)
    {
        if (prop != null && prop.getValue() != null)
            GeneralMethods.debug(this.getClass().toString(), "MakeRequest",
                    prop.name + "=" + prop.getValue().toString());
    }

    final Handler uiThreadCallback = new Handler();

    final Thread RequestThread = new Thread()
    {
        public void run()
        {
            try
            {

                SoapObject Request = new SoapObject(NAMESPACE, MethodName);

                // adding properties
                if (props != null)
                    for (PropertyInfo pi : props)
                    {
                        if (pi.getValue() != null
                                && isComplexType(pi.getValue().getClass()
                                        .getName()))
                        {
                            PropertyInfo complexProp = new PropertyInfo();
                            complexProp
                                    .setValue(getSoapClass(pi.getValue()));
                            complexProp.setName(pi.getName());
                            Request.addProperty(complexProp);

                        }
                        else
                            Request.addProperty(pi);
                    }

                // Set the web service envelope
                SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                        SoapEnvelope.VER11);
                envelope.dotNet = true;
                envelope.setOutputSoapObject(Request);
                HttpTransportSE androidHttpTransport = new HttpTransportSE(
                        URL, timeout);
                androidHttpTransport.debug = true; // TODO: comment it on
                                                    // finish debug

                // Load cookies
                List<HeaderProperty> httpHeaders = new ArrayList<HeaderProperty>();
                for (String cookie : cookies.keySet())
                {
                    httpHeaders.add(new HeaderProperty("Cookie", cookie
                            + "=" + cookies.get(cookie)));
                }

                // Call the web service and retrieve result


                @SuppressWarnings("rawtypes")
                List reshttpHeaders = androidHttpTransport.call(NAMESPACE
                        + MethodName, envelope, httpHeaders);


                // save cookies
                 Log.d("DEBUG OUTGOING XML",
                 androidHttpTransport.requestDump);
                androidHttpTransport.debug = true;
                 Log.d("DEBUG INCOMING XML=========================================",
                 androidHttpTransport.responseDump);
                if (reshttpHeaders != null)
                {
                    for (int i = 0; i < reshttpHeaders.size(); i++)
                    {
                        HeaderProperty hp = (HeaderProperty) reshttpHeaders
                                .get(i);
                        String key = hp.getKey();
                        String value = hp.getValue();
                        if (key != null && value != null)
                        {
                            if (key.equalsIgnoreCase("set-cookie"))
                            {
                                String cookieString = value.substring(0,
                                        value.indexOf(";"));

                                cookies.put(cookieString.substring(0,
                                        cookieString.indexOf("=")),
                                        cookieString.substring(cookieString
                                                .indexOf("=") + 1));
                                break;
                            }
                        }
                    }

                }
                // Log.i("test", httpHeaders.toString());
                // final Object res = envelope.getResponse();
                final Object res = envelope.getResponse();
                uiThreadCallback.post(new Runnable()
                {
                    public void run()
                    {
                        // Log.i("Talk2Doc", res.toString());
                        GeneralMethods.debug(this.getClass().toString(),
                                "MakeRequest", "Responce -> MethodName="
                                        + MethodName);

                        resListener.onGotResponse(res);

                    }
                });

            }
            catch (final Exception e)
            {
                GeneralMethods.debug(this.getClass().toString(),
                        "MakeRequest", "Error -> MethodName=" + MethodName
                                + ", Error=" + e.getMessage());
                uiThreadCallback.post(new Runnable()
                {
                    public void run()
                    {

                        e.printStackTrace();

                        if (e.getMessage().contains("login failed"))
                            resListener.onLoginError();
                        else
                        {

                            if (retries < 1
                                    || e.getClass() == SocketTimeoutException.class)
                                resListener.onResponseError(e);
                            else
                            {
                                // retry

                                MakeRequest(MethodName, props, resListener,
                                        timeout, retries - 1);

                            }

                        }

                    }
                });

            }
        }
    };
    RequestThread.start();

}
Gladi
  • 415
  • 4
  • 16
  • I'm using ksoap 2.6.5 version and connection is the same on all API. Try to download last ksoap release. – kinghomer Nov 22 '12 at 09:20
  • i did that. im using now version 3.0.0 RC.4 . still the same... – Gladi Nov 22 '12 at 10:26
  • try to set your project properties to 4.0. By the way i think problem is not ksoap. Then, post your method for making a soap call – kinghomer Nov 22 '12 at 10:35
  • hi kinghomer, in android 2.2 its was fine... im using the same method – Gladi Nov 22 '12 at 12:27
  • I added the code. you can see it now. – Gladi Nov 22 '12 at 12:37
  • Try to understand where code becomes slow. Try to use debug mode or to put between each line of code some Log.i("1"),Log.i("2"),Log.i("3")...etc... and see what is portion of code which gives problem so we can focalize attention just on it – kinghomer Nov 22 '12 at 13:45
  • hi kinghomer, i did that. the line that makes all slow is the Call() method. – Gladi Nov 22 '12 at 15:10

1 Answers1

0

Try this just set minimum sdk version to 8 in your project manifest file. and reply me the results. i.e android:minSdkVersion="8" in AndroidManifest file and reply me the results.

Sachin D
  • 1,370
  • 7
  • 29
  • 42
  • hey sachin D, it was like that all the time... () – Gladi Nov 22 '12 at 12:26
  • I've tried to connect the same webservice with httpclient without ksoap and all works just fine... but this application have very big communication layer... i prefer not to do so... – Gladi Nov 22 '12 at 12:31