How to consume Session dependent WCF services using Ksoap2-Android-ThrowExceptions

Exception or error:

I am using Ksoap2-Android for consuming the WCF Services.

For the dotnet client we keep the allowCookies="true" in our binding configuration and it sends the same sessionid and keeps my sessions intact in my WCF services (My services are
interdependent and use the sessions

Any one know any such setting for ksoap2-android, that will allow me to consume the
WCF service keeping my session intact on the server.

Currently when i make a new call to the service, the sessionid gets changed and all my
session variables clear out and loose their values.

How to solve:

In C# i do the next, just use the android methods to do this:

1.- Make the Http request,
2.- Make a Cookie Container of the first request.
3.- Put the cookieContainer over the second request, for example you can put in a bundle in a intent for the 2nd activity, and use this cookies for send the second http request…

My C# Code;

protected static void GetData()
        CookieContainer cookies = new CookieContainer();
        HttpWebRequest request1 = (HttpWebRequest)WebRequest.Create("");
        request1.CookieContainer = cookies;
        HttpWebResponse response1 = (HttpWebResponse)request1.GetResponse();
        StreamReader responseReader1 = new StreamReader(response1.GetResponseStream());
        Response1 = responseReader1.ReadToEnd();

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
        request.CookieContainer = cookies;
        request.Method = "GET";
        request1.KeepAlive = true;
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            StreamReader responseReader = new StreamReader(response.GetResponseStream());
            Response = responseReader.ReadToEnd();
            if (Response.Contains("Server Error in '/Verification' Application."))
                Console.WriteLine("Empty Registry" + Url);
        catch (WebException ex)
            if (ex.Response != null)
                Console.WriteLine("Failed at: " + Url);
            if (ex.Status == WebExceptionStatus.ProtocolError)
                if (((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.NotFound)
            else if (ex.Status == WebExceptionStatus.NameResolutionFailure)


I do That for keep the sesionID of the first request, and later, in the second request, i add the cookieContainer (because the server requires me) (to make a bot search) ;)… hope this give you ideas.

Leave a Reply

Your email address will not be published. Required fields are marked *