2010-09-12 16 views
9

Iam tratando de conectar mi aplicación a un servicio WCF que he creado en asp.net. El servicio se ejecuta en mi localmachine: http://localhost:8080/Service.svc/Aplicación de Android que se conecta a un servicio web - no funciona

Pero, por alguna razón mi Android no se puede conectar a esta dirección http-.

Este es el error:

09-12 14: 50: 44.540: WARN/System.err (593): org.apache.http.conn.HttpHostConnectException: Conexión a http://127.0.0.1:8080 se negó
esto es el método en wcf, intento devolver una colección con algunos valores.

 /// <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; 
    } 


y es así como la conexión en el androide parece:

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(); 
    } 
} 

Respuesta

15

127.0.0.1 se refiere a localhost en el emulador, no por la máquina.

Utilice 10.0.2.2 para conectarse a su máquina host.

hará también asegurarse de que ha solicitado el permiso INTERNET en su AndroidManifest.xml

+0

gracias funcionó, – Troj

+0

¿Sabe usted cómo es posible leer los datos que se han enviado? – Troj

+0

Puede usar WireShark en la máquina host para este propósito. –

Cuestiones relacionadas