2009-07-28 5 views

Antwort

1

Danke für dieses Web-Service-Android-Client zu machen Sehen Frage hier: Unresolved Host Exception Android

Aufruf der Rest-Service ist nur eine Frage der Erstellung der HttpResponse und Verarbeitung der zurückgegebenen XML/JSON/Wert.

+0

Wenn nur das etwas zu erledigen, war das einfach ... –

5

Sie haben wahrscheinlich etwas gefunden, das funktioniert, aber ich stolperte über diesen Thread, und für andere kann folgendes nützlich sein.

Ich bevorzuge REST-Anwendung mit MVC und Android. -www.asp.net/mvc (gute Video-Tutorials)

Um einen Server zu erstellen:

http:// omaralzabir.com/create_rest_api_using_asp_net_mvc_that_speaks_both_json_and_plain_xml/

public class TestingController : Controller { 
    /// <summary> 
    /// Test 
    /// </summary> 
    /// <returns></returns> 
    public ActionResult GetString() { 
     return Content("A Result <orasxml id='testid'/>"); 
    } 
} 

Und gesetzt Global.asax:

// Test routes.MapRoute ("test", "{Seite} .Mvc/tester", neue {controller = "Testing", Aktion = "GetString", Page = defaultPage});

Andoid Entwicklung Client-Code beispiele:

http://www.smnirven.com/?p=15

http://senior.ceng.metu.edu.tr/2009/praeda/2009/01/11/a-simple-restful -client-at-android/

public String GetData() {

//Note, do not use http:// in host name. I did not get localhost-adress working, but 
    //hosted a page in IIS instead, and it worked. 
    HttpHost target = new HttpHost("www.example,com",80); 
    HttpGet get = new HttpGet("/tester"); 
    String result=null; 
    HttpEntity entity = null; 
    HttpClient client = new DefaultHttpClient(); 
    try { 
     HttpResponse response=client.execute(target, get); 
     entity = response.getEntity(); 
     result = EntityUtils.toString(entity); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } finally { 
    if (entity!=null) 
    try { 
     entity.consumeContent(); 
    } catch (IOException e) {} 
    } 
    return result; 

} 0.123.
//Display on buttontext, must create buttoon with ButtonReload as id... 
    final Button btn = (Button) findViewById(R.id.ButtonReload); 
    btn.setText(testString); 

Tipps über REST für Android Gestaltung:

http://www.youtube.com/watch?v=xHXn3Kg2IQE

http://www.infoq.com/articles/rest- Einführung

Allgemeine Android Hilfe:

http://mobile.tutsplus.com/tutorials/android/introduction-to-android-development/

h t t p://www.youtube.com/watch?v=lqopIf-bA54 & feature = verwandt