manish-kukreja / ksoap2-android

Automatically exported from code.google.com/p/ksoap2-android
0 stars 0 forks source link

How to get cookie from SOAP (using Android) and than use it across the methods in my app #42

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hello ppl.. i think this is my last hope where i can find some solution about 
my issue.

I'm using ksoap2 with Android to connect to my web service (SOAP 1.1). I have 
some methods to LogOn, LogOff, GetUserProfile etc. I'm sniffing the connection 
with Wireshark and everything is fine (it connects successfully).
But the problem is when i call the LogOff method or GetUserProfile, it gives me 
exception from the server and it says "User not logged in", i understand why, 
it's becouse i don't get the cookie and everytime i call them it won't 
recognize me. So i want some help to solve that issue. I want to get the cookie 
after i use LogOn method and than use the same cookie for the User across the 
other methods as LogOff or GetUserProfile.

Here is my class with the Methods..

 public class Methods {

private static final String SOAP_ACTION="http://tempuri.org/E_banka/TSM2/LogOn";
private static final String METHOD_NAME="LogOn";
private static final String NAMESPACE="http://tempuri.org/E_banka/TSM2";
private static final String 
URL="http://wsstore.com/e-banka/WebServisi/WSAuth.asmx";

public static final String LOG_TAG ="error_msg";
//public static final String res = strRes;

public static String res = " ";
public static String resoff = " ";
public static String strproff1 = " ";
public static String strproff2 = " ";
public static String strproff3 = " ";

public static void LogOn(String username, String password) 
{
    SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
    Request.addProperty("strUsername", username);
    Request.addProperty("strPassword", password);
    Request.addProperty("strMessage", "");

    SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    soapEnvelope.dotNet = true;
    soapEnvelope.setOutputSoapObject(Request);

    AndroidHttpTransport aht = new AndroidHttpTransport(URL);
  try {
        aht.call(SOAP_ACTION, soapEnvelope);

        SoapObject soapIn = (SoapObject)soapEnvelope.bodyIn;
        String strRes = soapIn.getProperty("LogOnResult").toString();

        res = strRes;
  }
  catch(Exception e)
  {
      e.printStackTrace();
      Log.d(LOG_TAG, "Error: " + e);
  }
}

public static void LogOff()
{   
    try {
        SoapObject Request = new SoapObject(NAMESPACE, "LogOn");
        Request.addProperty("strMessage", "");
        SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        soapEnvelope.dotNet = true;
        soapEnvelope.setOutputSoapObject(Request);
        AndroidHttpTransport aht = new AndroidHttpTransport(URL);

        aht.call("http://tempuri.org/E_banka/TSM2/LogOff", soapEnvelope);
        SoapObject soapIn = (SoapObject)soapEnvelope.bodyIn;
        String strRes2 = soapIn.getProperty("LogOffResult").toString();

        resoff = strRes2;
  }
  catch(Exception e)
  {
      e.printStackTrace();
      Log.d(LOG_TAG, "Error: " + e);
  }
}

public static void GetProfile()
{
     try {
            SoapObject Request = new SoapObject(NAMESPACE, "GetUserProfile");
            Request.addProperty("uiUser", null);
            Request.addProperty("strMessage", "");
            SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            soapEnvelope.dotNet = true;
            soapEnvelope.setOutputSoapObject(Request);
            AndroidHttpTransport aht = new AndroidHttpTransport(URL);

            aht.call("http://tempuri.org/E_banka/TSM2/GetUserProfile", soapEnvelope);
            SoapObject soapIn = (SoapObject)soapEnvelope.bodyIn;
            String strProf1 = soapIn.getProperty("FirstLastName").toString();
            String strProf2 = soapIn.getProperty("Jazik").toString();
            String strProf3 = soapIn.getProperty("SertNum").toString();

            strproff1 = strProf1;
            strproff2 = strProf2;
            strproff3 = strProf3;
      }
      catch(Exception e)
      {
          e.printStackTrace();
          Log.d(LOG_TAG, "Error: " + e);
      }
}

public String getRes() { return res; }
public void setRes(String strRes) { res = strRes; }

public String getResOff() { return resoff; }
public void setResOff(String strRes2) { resoff = strRes2; }

public String getProf1() { return strproff1; }
public void setProf1(String strProf1) { strproff1 = strProf1; }

public String getProf2() { return strproff2; }
public void setProf2(String strProf2) { strproff2 = strProf2; }

public String getProf3() { return strproff3; }
public void setProf3(String strProf3) { strproff3 = strProf3; } }

Here is my main Activity..

public class Main extends Activity {
/** Called when the activity is first created. */

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    //TextView tv = (TextView) findViewById(R.id.TextView01);
    final EditText et1 = (EditText) findViewById(R.id.EditText01);
    final EditText et2 = (EditText) findViewById(R.id.EditText02);
    Button btn = (Button) findViewById(R.id.Button01);
    final TextView txt1 = (TextView) findViewById(R.id.TextView02);
    final TextView txt2 = (TextView) findViewById(R.id.TextView03);
    final TextView txt3 = (TextView) findViewById(R.id.TextView04);

    btn.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
             Methods.LogOn(et1.getText().toString(),et2.getText().toString());
                if(Methods.res.equals("1"))
                {
                    Toast.makeText(Main.this, "Logon Successful", Toast.LENGTH_SHORT).show();

                    Methods.GetProfile();
                    txt1.setText(Methods.strproff1);
                    txt2.setText(Methods.strproff2);
                    txt3.setText(Methods.strproff3);

                    //Methods.LogOff();
                }
                else Toast.makeText(Main.this, "Logon not Successful", Toast.LENGTH_SHORT).show();
        }
    });

}
}

When i use Methods.GetProfile() or Methods.LogOff() i get LogOffResult=-20 and 
that means "USER_NOT_LOGGED", it's the same for GetProfile.

Any solution about the cookie ? i searched almost everything and there isn't 
even close solution about solving this problem :/
I've tried some methods that i've found but still nothing..

Original issue reported on code.google.com by Aleksand...@gmail.com on 7 Dec 2010 at 1:48

GoogleCodeExporter commented 9 years ago

Original comment by mosa...@gmail.com on 7 Dec 2010 at 4:44

GoogleCodeExporter commented 9 years ago
Cookie support is currently in development by a contributor. Feel free to help 
out. The github clone is public. See details in the linked issue 25.

Original comment by mosa...@gmail.com on 7 Dec 2010 at 4:44