Jump to content

authentification avec web service


Recommended Posts

salut,,

je suis entrain de faire module authentification avec android

je travail avec sdk 4.0.3 et mysql

pour accéder au base de donnée mysql j'utilise web service

la table user contient deux attributs : login,mail

et j'ai comme valeur : test,test

le code que j'utilise est :

package com.android.gd;

import java.io.BufferedReader;

import java.io.InputStream;

import java.io.InputStreamReader;

import org.apache.http.HttpResponse;

import org.apache.http.client.methods.HttpGet;

import org.apache.http.impl.client.DefaultHttpClient;

import org.ksoap2.SoapEnvelope;

import org.ksoap2.serialization.SoapObject;

import org.ksoap2.serialization.SoapSerializationEnvelope;

import org.ksoap2.transport.HttpTransportSE;

import android.app.Activity;

import android.os.AsyncTask;

import android.os.Bundle;

import android.view.View;

import android.widget.TextView;

import android.widget.Toast;

public class ProjectGDActivity extends Activity {

//private TextView textView;

private String METHOD_NAME ="authentification"; // our webservice method name

private String NAMESPACE ="http://gd.com"; // Here package name in

// webservice with reverse

// order.

private String SOAP_ACTION = NAMESPACE + METHOD_NAME; // NAMESPACE + method

// name

private static final String URL ="http://192.168.1.98:8082/wsgd/services/gd?wsdl"; // you

TextView tv;

TextView tv2;

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

TaskWs task = new TaskWs();

task.execute();

}

private class TaskWs extends AsyncTask<String, Void, String> {

@Override

protected void onPostExecute(String result) {

tv.setText(result);

}

@Override

protected String doInBackground(String... params) {

String v="addi";

Object result = v ;

tv = (TextView) findViewById(R.id.Ch_Login);

tv2 = (TextView) findViewById(R.id.Ch_Passwd );

try {

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

request.addProperty("login", "test");

request.addProperty("mail", "test");

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(

SoapEnvelope.VER11);

envelope.dotNet = true;

envelope.setOutputSoapObject(request);

HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

androidHttpTransport.call(SOAP_ACTION,envelope);

result = envelope.getResponse();

//((TextView) findViewById (R.id.txtAddition)).setText("Addition : "+result.toString());

} catch (Exception E) {

E.printStackTrace();

//((TextView) findViewById (R.id.txtAddition)).setText("ERROR:" + E.getClass().getName() + ":" + E.getMessage());

}

// TODO Auto-generated method stub

return result.toString();

}

}

public void readWebpage(View view) {

}

}

et j'ai dans le projet web qui contient le web service cette methode "authentification"

public boolean authentification(String login,String mail){

UsersHome u=new UsersHome();

UsersId us=new UsersId(login, mail);

List<Users> listu=u.findByCriteria(us);

if(listu.size()>0){

System.err.println("succes");

return true;

}

else{

System.err.println("echec");

return false;

}

}

mais je trouve des problème avec cet exemple puisque il se plante dans l'interface d'authentification

merci d'avance

Link to comment
Share on other sites

  • 3 months later...

Bonjour, je crois simplement que les services web SOAP ne sont pas atteignables depuis un client android.

Je bute dessus depuis pas mal de temps, j'ai écumé le web et jamais trouvé la solution au plantage de la fonction qui appelle le service :

androidHttpTransport.call(SOAP_ACTION,envelope); l'erreur est là, mais personne ne sait expliquer.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...