0

I'm very new to webservices. Currently i'm working on an android app which needs to authenticate the user through webservices( means the username and password are stored in the remote database). Can anyone tell me, how can i accomplish this?

CAMOBAP
  • 5,523
  • 8
  • 58
  • 93
user456
  • 61
  • 1
  • 7

2 Answers2

0

U can use REST webservice please look into the below link

Android Connecting to remote server Mysql

Goofy
  • 6,098
  • 17
  • 90
  • 156
0

I am not sure what webservices you are using. If your Ksoap 2 webservice.

CheckNetwork C0de

 public class CheckNetwork {


private static final String TAG = CheckNetwork.class.getSimpleName();



public static boolean isInternetAvailable(Context context)
{
    NetworkInfo info = (NetworkInfo) ((ConnectivityManager)
       context.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();

    if (info == null)
    {
         Log.d(TAG,"no internet connection");
         //Toast.makeText(context, "No Internet Connection", 1000);
         return false;
    }
    else
    {
        if(info.isConnected())
        {
            Log.d(TAG," internet connection available...");
            return true;
        }
        else
        {
            Log.d(TAG," internet connection");
            return true;
        }

    }
}
 }

In your Activity onCreate()

  Name =mEditTextUsername.getText().toString();
  Pass= mEditTextPassword.getText().toString();
  new TheTask().execute(Name,Pass);

class TheTask extends AsyncTask<String, Integer, Void>{
    ProgressDialog pd;

    @Override
    protected void onPreExecute() {
        pd=new ProgressDialog(Login.this);
        pd.setTitle("Authenticating");
        pd.show();

    }

    @Override
    protected Void doInBackground(String... params) {   
        authenticate(params[0],params[1]);
        return null;

    }

    @Override
    protected void onPostExecute(Void result) {
        pd.dismiss();
       }
    public void authenticate(String name, String pass)
    {
    if(CheckNetwork.isInternetAvailable(Login.this))
    {

        SoapObject request = new SoapObject("NameSpace", "method name");
                PropertyInfo loginreq = new PropertyInfo();
        loginreq.name="LoginReq";
        loginreq.type=String.class;
                    loginreq.setValue(your request value);
                    request.addProperty(loginreq);  
            SoapSerializationEnvelope envelop = new      SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelop.setOutputSoapObject(request);
            System.out.println("Request is"+request); 

        HttpTransportSE androidHttpTransport = new   HttpTransportSE ("your wsdl link");
        androidHttpTransport.debug=true;                                                                  androidHttpTransport.call("YOUR LOGINREQUST", envelop);
        SoapObject response=(SoapObject) envelop.bodyIn;
        System.out.println("Response is......"+response.toString());//get your response
    }   

Webservice responds with a code tag 1 for sucess and 0 for failure. This also depends on the design of webservice response. The above code works using soap webservice. Also take a look at this link. how to connect android and mysql server?.

Community
  • 1
  • 1
Raghunandan
  • 132,755
  • 26
  • 225
  • 256