Iam sta tentando di connettere la mia app a un servizio WCF che ho creato in asp.net. Il servizio è attivo sul mio localmachine: http://localhost:8080/Service.svc/Applicazione Android che si collega a un servizio web - non funzionante
Ma per alcuni motivi il mio Android non può collegarsi a questo http-indirizzo.
Questo è l'errore:
09-12 14: 50: 44,540: WARN/System.err (593): org.apache.http.conn.HttpHostConnectException: Collegamento a http://127.0.0.1:8080 rifiutato
questo è il metodo in wcf, Iam sta cercando di restituire una collezione con alcuni valori.
/// <returns>An enumeration of the (id, item) pairs. Returns null if no items are present</returns>
protected override IEnumerable<KeyValuePair<string, SampleItem>> OnGetItems()
{
// TODO: Change the sample implementation here
if (items.Count == 0)
{
items.Add("A", new SampleItem() { Value = "A" });
items.Add("B", new SampleItem() { Value = "B" });
items.Add("C", new SampleItem() { Value = "C" });
}
return this.items;
}
e in questo modo il collegamento in Android si presenta come:
public void getData(String url)
{
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
HttpResponse response;
try
{
response = httpClient.execute(httpGet);
Log.i(TAG,response.getStatusLine().toString());
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}/* catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} */catch (Exception e){
e.printStackTrace();
}finally{
httpGet.abort();
}
}
grazie ha funzionato, – Troj
fai a sapere come è possibile leggere i dati che è stato inviato? – Troj
È possibile utilizzare WireShark sulla macchina host esattamente per questo scopo. –