pshah
pshah

Reputation: 19

How do I parse a KSOAP endpoint in android , keeping the same session used for login and then request other endpoints within the same Web-session?

I have a set of endpoints developed in the KSOAP format in Asp.net. The website has a login form which takes Email id and pass in order to log user in. Now the behavior of the website is that, it saves the Email id in the local storage as key and the website uses the same session to retrieve feedback received on that Email and feedback inserted by that Email id. Now on the Android Native side, When request to log in it logs in successfully though return null when retrieve feedback is called as it might be initiating a new session. Thus I am just getting a null object as there is no Email key stored in the local storage. Please help me in order to maintain same session and after login I can request other relevant endpoints.

I have tried using the same Envelop object, using it both the both http requests, also tried to save header but nothing worked.

For Logging In

public class LoginWebservice {
        //Namespace of the Webservice - can be found in WSDL
        private static String NAMESPACE = "http://tempuri.org/";
        //Webservice URL - WSDL File location
        private static String URL = "https://www.xxxxxx/feedback/Webservice1.asmx?WSDL";

        //SOAP Action URI again Namespace + Web method name
        private static String SOAP_ACTION = "http://tempuri.org/";

        public static boolean invokeLoginWS(String userName,String passWord, String webMethName) {
            boolean loginStatus = false;
            // Create request
            SoapObject request = new SoapObject(NAMESPACE, webMethName);
            // Property which holds input parameters
            PropertyInfo unamePI = new PropertyInfo();
            PropertyInfo passPI = new PropertyInfo();
            // Set Username
            unamePI.setName("Email");
            // Set Value
            unamePI.setValue(userName);
            // Set dataType
            unamePI.setType(String.class);
            // Add the property to request object
            request.addProperty(unamePI);
            //Set Password
            passPI.setName("Password");
            //Set dataType
            passPI.setValue(passWord);
            //Set dataType
            passPI.setType(String.class);
            //Add the property to request object
            request.addProperty(passPI);
            // Create envelope
            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                    SoapEnvelope.VER11);
            envelope.dotNet = true;
            // Set output SOAP object
            envelope.setOutputSoapObject(request);


            // Create HTTP call object
            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

            try {
                // Invoke web service
                androidHttpTransport.call(SOAP_ACTION+webMethName, envelope);
                // Get the response
                SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
                // Assign it to  boolean variable variable
                loginStatus = Boolean.parseBoolean(response.toString());
                Log.w("LoginStatuslog",Boolean.toString(loginStatus));

            } catch (Exception e) {
                //Assign Error Status true in static variable 'errored'
               // CheckDNLoginActivity.errored = true;
                e.printStackTrace();
            }
            //Return booleam to calling object
            return loginStatus;
        }
-----------------------------------------------------------------------
For retrieving relevant Feedbacks




    public static String invokeJSONWS(String methName) {
        // Create request
        SoapObject request = new SoapObject(NAMESPACE,methName);
        // Property which holds input parameters
       /* PropertyInfo paramPI = new PropertyInfo();
        // Set Name
        // Set dataType
        paramPI.setType(String.class);
        // Add the property to request object
        request.addProperty(paramPI);*/
        // Create envelope

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
           SoapEnvelope.VER11);
        envelope.dotNet = true;
        // Set output SOAP object
        envelope.setOutputSoapObject(request);
        envelope.headerOut = new Element[1];
        envelope.headerOut[0] = LoginWebservice.buildAuthHeader();
        // Create HTTP call object
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

        try {
            // Invole web service
            androidHttpTransport.call(SOAP_ACTION+methName, envelope);
            // Get the response
            SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
            Log.e("Soap Res",response.toString());
            // Assign it to static variable
            responseJSON = response.toString();
            JSONArray json = new JSONArray(responseJSON);
            Log.d("Response", json.toString());

        } catch (Exception e) {
            e.printStackTrace();
        }
            return responseJSON;
    }

It returns a Null object

Upvotes: 1

Views: 27

Answers (0)

Related Questions