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?
Asked
Active
Viewed 297 times
0
-
1what webservice you going to use?any ideas – vinothp Nov 05 '12 at 12:42
-
you can visit here http://stackoverflow.com/questions/9256647/login-check-in-server-side/9256749#9256749 – Ajay Nov 05 '12 at 12:55
2 Answers
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