Sto creando un server in .NET e un'applicazione client per Android. Vorrei implementare un metodo di autenticazione che manda nome utente e password al server e un server restituisce una stringa di sessione.Come utilizzare il servizio WCF con Android
Non ho familiarità con WCF, quindi gradirei davvero il vostro aiuto.
in Java ho scritto il seguente metodo:
private void Login()
{
HttpClient httpClient = new DefaultHttpClient();
try
{
String url = "http://192.168.1.5:8000/Login?username=test&password=test";
HttpGet method = new HttpGet(new URI(url));
HttpResponse response = httpClient.execute(method);
if (response != null)
{
Log.i("login", "received " + getResponse(response.getEntity()));
}
else
{
Log.i("login", "got a null response");
}
} catch (IOException e) {
Log.e("error", e.getMessage());
} catch (URISyntaxException e) {
Log.e("error", e.getMessage());
}
}
private String getResponse(HttpEntity entity)
{
String response = "";
try
{
int length = (int) entity.getContentLength();
StringBuffer sb = new StringBuffer(length);
InputStreamReader isr = new InputStreamReader(entity.getContent(), "UTF-8");
char buff[] = new char[length];
int cnt;
while ((cnt = isr.read(buff, 0, length - 1)) > 0)
{
sb.append(buff, 0, cnt);
}
response = sb.toString();
isr.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
return response;
}
Ma sul lato server finora non ho capito nulla.
Sarei davvero grato se qualcuno potesse spiegare come creare una stringa di metodo appropriata Login (nome utente stringa, password stringa) con impostazioni App.config appropriate e interfaccia con firma appropriata [OperationContract] per leggere questi due parametri da client e rispondere con una stringa di sessione.
Grazie!
Mi piacerebbe vedere un modo per utilizzare wcf serializzato su Android. ora sarebbe bello. –