0

Hi i developed one login form calling soap webservices.it is success fully worked for me...But now i implement the one part.here i will make session management...how is making session management in dis login form.please guide me.

dis is my android coding part:

  package com.soap;
  import org.ksoap2.SoapEnvelope;
  import org.ksoap2.serialization.PropertyInfo;
  import org.ksoap2.serialization.SoapObject;
  import org.ksoap2.serialization.SoapPrimitive;
  import org.ksoap2.serialization.SoapSerializationEnvelope;
  import org.ksoap2.transport.HttpTransportSE;


   import android.app.Activity;
   import android.content.Intent;
   import android.os.Bundle;
   import android.view.View;
   import android.widget.Button;
   import android.widget.CheckBox;
   import android.widget.EditText;
   import android.widget.TextView;
   import android.content.SharedPreferences;
   import android.content.Context;
   public class Login extends Activity {
   private static final String SPF_NAME = "vidslogin";
   private static final String USERNAME = "username";
   private static final String PASSWORD = "password";

   EditText userName,userPassword;
   private final String NAMESPACE = "http://ws.userlogin.com";
   private final String URL = "http://192.168.1.168:8085/LoginSoap/services/Login?wsdl";
   private final String SOAP_ACTION = "http://ws.userlogin.com/authentication";
   private final String METHOD_NAME = "authentication";
   /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.login);

 Button logout = (Button) findViewById(R.id.btn_logout);
  logout.setOnClickListener(new View.OnClickListener() {

 public void onClick(View v) {
 // Switching to Register screen
  Intent i = new Intent(getApplicationContext(), Login.class);
  startActivity(i);
  }
  });

 Button login = (Button) findViewById(R.id.btn_login);
 login.setOnClickListener(new View.OnClickListener() {

 public void onClick(View arg0) {
  loginAction();

     }
     });
    }

   private void loginAction(){
 SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

    EditText userName = (EditText) findViewById(R.id.tf_userName);
    String user_Name = userName.getText().toString();
    EditText userPassword = (EditText) findViewById(R.id.tf_password);
    String user_Password = userPassword.getText().toString();

  //Pass value for userName variable of the web service
    PropertyInfo unameProp =new PropertyInfo();
    unameProp.setName("userName");//Define the variable name in the web service method
    unameProp.setValue(user_Name);//set value for userName variable
    unameProp.setType(String.class);//Define the type of the variable
    request.addProperty(unameProp);//Pass properties to the variable

  //Pass value for Password variable of the web service
    PropertyInfo passwordProp =new PropertyInfo();
    passwordProp.setName("password");
    passwordProp.setValue(user_Password);
    passwordProp.setType(String.class);
    request.addProperty(passwordProp);

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.setOutputSoapObject(request);
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

    try{
        androidHttpTransport.call(SOAP_ACTION, envelope);
           SoapPrimitive response = (SoapPrimitive)envelope.getResponse();

           TextView result = (TextView) findViewById(R.id.tv_status);
           result.setText(response.toString());

    }
    catch(Exception e){

    }
   }

    }

Guide me how is make session in android application. please give me some ideas.

Krishna Veni
  • 2,217
  • 8
  • 27
  • 53

1 Answers1

1

There are various ways to implement Session Management. I would suggest you should try using Cookies

The new ksoap releases ( ksoap 2.5.4 I guess) has cookie support built that enables you to pass cookies in and out of your application.

Details

The HttpTransportSE class exposes the method call that, beyond the required SOAP parameters, also accepts a List of HeaderProperty instances. It also returns a like List. This provides the ability to append additional headers to the request and review the returned headers. Since a cookie is just one of those header, one can use this facility to send and receive cookies.

Cookies as simply received from the web service and sent to the web service as headers in the HTTP preamble. In order to use cookies with the ksoap2-android, one needs to save any returned cookies and return them with subsequent calls to the web service.

Example

  List respHeaders = android_http.call(SOAP_ACTION, envelope2, reqHeaders); 
  for(int ix=0; ix<respHeaders.size(); ix++) { 
  HeaderProperty hp = (HeaderProperty)respHeaders.get(ix); 
  System.out.println("Header"+ix+"="+hp.getKey()+" / "+hp.getValue()); 

So, for Session Management you could just save your Cookies and set them on a request.

Here is a question that shows How to save and return cookies to web service

Information Source: ksoap2-android and cookies

Community
  • 1
  • 1
Parth Doshi
  • 4,200
  • 15
  • 79
  • 129
  • how is used above coding.because i can't understand dis coding part.please help me – Krishna Veni Jul 19 '12 at 12:24
  • what that is doing is that it is getting a list of response headers and then you can iterate through it. If you see the question link that I have given you will understand that it is done to store the cookies for session management – Parth Doshi Jul 19 '12 at 12:27
  • hi i can't develop do dis.please send me some example with clear coding explaination. – Krishna Veni Jul 20 '12 at 05:14