RESTful Web service - Android

Last Updated:

  1. &roid junkie

    &roid junkie New Member

    Hi All,

    I have been following this forum for several weeks now, and finally decided to post my question and see if anybody can help me...

    I want to create an Android App (client-server) that will interact with already running web server.
    (think of something similar like the Facebook App - where the user is able (thru a custom GUI) to view/add/delete photos, edit his blog..etc).
    I want to use the code I already have written for the Website.
    I have decided to use REST as opposed to SOAP, because I am using WCF (which is .svc), and it's more secure for HTTP transfer.

    Here are my 2 questions:

    • What data format is more reliable and simple to use? JSON or Open Data protocol ( ?
    • How do I make the first communication between the server and the app?
    I need to call the server, and then get a response (just to test the connection).
    Please include some code as an example or a link to where I can lern more!


    &roid junkie

  2. DotNetWebs

    DotNetWebs New Member

    Hi there.

    First post for me too. I am in similar situation. I have be developing in .net since it's launch but have only just started with Android.

    I have an existing C# application which I have just connected to a WCF web service exposing JSON data to an Android client.

    I have found two sources invaluable in pointing me in the right direction:

    1. The O'Reilly book RESTful .NET by John Flanders.


    2. This blog post:

    Eddie@Blog: Comsuming WCF Services With Android

    I have already had to modify the code above to handle large data streams but it was enough to get me started.


  3. &roid junkie

    &roid junkie New Member

    Thanks Dotty!
    At the moment I have 4 different Android books, but none of them explain it in detail...
    I will definetly get this book! AND the blog post is very helpful!

  4. javarose

    javarose New Member


    I am having Restful webservice and Android client for Restful Webservice in Java. I sucessfully coded to get the respose using HttpGet() method. but i coudnt how to Post using HttpPost() to Restful Service from Android.

    Here are my Webservice:
    import java.util.ArrayList;
    import java.util.List;
    import java.util.TreeMap;
    import com.sun.jersey.spi.resource.Singleton;
    public class CustomerResource {
    private TreeMap<Integer, Customer> customerMap = new TreeMap<Integer, Customer>();
    public CustomerResource() {
    // hardcode a single customer into the database for demonstration
    // purposes
    Customer customer = new Customer();
    customer.setName("Harold Abernathy");
    customer.setAddress("Sheffield, UK");
    public List<Customer> getCustomers() {
    List<Customer> customers = new ArrayList<Customer>();
    return customers;
    public Customer getCustomer(@PathParam("id") int cId) {
    return customerMap.get(cId);
    public String addCustomer(Customer customer) {
    int id = customerMap.size();
    customerMap.put(id, customer);
    return "Customer " + customer.getName() + " added with Id " + id;


    My Android Code

    I dont know how to give the URL for Post Method in HttpPost()

    void post1()
    // String xml = "<customer><address>1223</address><name>niwin</name></customer>";

    String xml = ​
    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"

    "<customers><customer><address>Sheffield, UK</address>"

    "<id>0</id><name>Harold Abernathy</name></customer></customers>";
    StringEntity se =
    HttpPost postRequest =
    new HttpPost("");
    try {
    se =
    new StringEntity(xml,HTTP.UTF_8);

    HttpClient httpclient =
    new DefaultHttpClient();
    //HttpResponse resp=httpclient.execute(postRequest);

    BasicHttpResponse httpResponse;
    try {
    httpResponse = (BasicHttpResponse) httpclient.execute(postRequest);
    catch (ClientProtocolException e) {
    // TODO Auto-generated catch block

    } ​
    catch (IOException e) {
    // TODO Auto-generated catch block


    } ​
    catch (UnsupportedEncodingException e) {
    // TODO Auto-generated catch block

    "UnsupportedEncodingException ","Resp:\n"+e.getMessage());

    The above programs execute with error free but i am not getting the Posted values in Webservice
    Please Help me how to overcome this one?
  5. harishandro

    harishandro New Member

    can anyone tell how to use webservices in android ..suggest any book

Share This Page