Skip to content Skip to sidebar Skip to footer

Consuming A Soap Webservice Without Ksoap2 In Android

In my Android application, i'm using ksoap2 library for consuming a soap ( & .net) webservice. It works correctly but it's very slow (for parsing, controls, loops and Base64ToB

Solution 1:

What do you mean slow? It does a http request and then parses the response. You have to do this in an async task. Memory usage will depend on the response you get. Maybe you are requesting way too much. See the wiki on how to debug!

Solution 2:

I have another problem with KSoap2. Unfortunately, ksoap2 library is not working with my webservices. So at last, I have done with default http post.

I hope this will help for someone in future.

private String makeHttpRequest(){
        try{
            Stringrequest="<?xml version=\"1.0\" encoding=\"UTF-8\"?><SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns1=\"http://tempuri.org/\">"
                    +"<SOAP-ENV:Body>"
                    + "<ns1:Connect>"
                    + "<ns1:lstr_Login>xxxxx</ns1:lstr_Login>"
                    +"</ns1:Connect>"
                    +"</SOAP-ENV:Body>"
                    +"</SOAP-ENV:Envelope>";

            StringsoapAction="http://tempuri.org/Connect"; //this would be your soapAction from wsdlStringEntityse=newStringEntity(request, HTTP.UTF_8);
            DefaultHttpClientclient=newDefaultHttpClient();
            HttpPosthttpPost=newHttpPost(newURI("http://xxxxxxxx.com/Storefront.asmx"));

            httpPost.addHeader("Content-Type", "text/xml; charset=utf-8");
            httpPost.addHeader("SOAPAction", soapAction);

            httpPost.setEntity(se);
            HttpResponseresponse= client.execute(httpPost);
            intresponseStatusCode= response.getStatusLine().getStatusCode();
            Log.d(TAG, "HTTP Status code:"+responseStatusCode);
            if(responseStatusCode>=200 && responseStatusCode<300){
                //we got the success response from server. Now retrieve the value and go for usage.StringresponseStr= EntityUtils.toString(response.getEntity());
                //use this responseStr to parse with pullparsers or any
                Log.d("Response", "Response:: "+ responseStr);
                return responseStr;
            }
        }catch(Exception e){
            //Write the proper catch blocks for exceptions
            Log.e("Response Exception" , e.getMessage()+"",e);
        }
        returnnull;
    }

Post a Comment for "Consuming A Soap Webservice Without Ksoap2 In Android"