Go Back   Android Forums > Android Discussion > Android Applications
Android Applications All the information you could ever want about Android Applications. Learn about apps and get help with them... all here! New apps can be found and announced in the Applications Announcements forum linked below.

test: Reply
 
LinkBack Thread Tools
Old August 24th, 2010, 05:30 PM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Aug 2010
Posts: 2
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default RESTful Web service - Android

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 (odata.org) ?
  • 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!

Thanks

&roid junkie

Advertisements
&roid junkie is offline  
Reply With Quote
sponsored links
Old August 26th, 2010, 10:37 AM   #2 (permalink)
New Member
 
Join Date: Aug 2010
Posts: 1
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

and

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.

Regards

Dotty
DotNetWebs is offline  
Reply With Quote
Old August 26th, 2010, 11:05 AM   #3 (permalink)
New Member
Thread Author (OP)
 
Join Date: Aug 2010
Posts: 2
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

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!

Cheers
&roid junkie is offline  
Reply With Quote
Old October 12th, 2010, 06:09 AM   #4 (permalink)
New Member
 
Join Date: Oct 2010
Posts: 1
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

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:
package com.myeclipseide.ws;
import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import com.sun.jersey.spi.resource.Singleton;
@Produces("application/xml")
@Path("customers")
@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");
addCustomer(customer);
}
@GET
public List<Customer> getCustomers() {
List<Customer> customers = new ArrayList<Customer>();
customers.addAll(customerMap.values());
return customers;
}
@GET
@Path("{id}")
public Customer getCustomer(@PathParam("id") int cId) {
return customerMap.get(cId);
}
@POST
@Path("add")
@Produces("text/plain")
@Consumes("application/xml")
public String addCustomer(Customer customer) {
int id = customerMap.size();
customer.setId(id);
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()

public
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 =
null;
HttpPost postRequest =
new HttpPost("http://192.168.2.23:1234/RestfulWS/services/customers/add");
try {
se =
new StringEntity(xml,HTTP.UTF_8);
se.setContentType(
"text/xml");
postRequest.setHeader(
"Content-Type","application/soap+xml;charset=UTF-8");
postRequest.setEntity(se);

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


BasicHttpResponse httpResponse;
try {
httpResponse = (BasicHttpResponse) httpclient.execute(postRequest);
Log.d(
"HTTPStatus",httpResponse.getStatusLine().toString());
}
catch (ClientProtocolException e) {
// TODO Auto-generated catch block

e.printStackTrace();
}
catch (IOException e) {
// TODO Auto-generated catch block

e.printStackTrace();
}



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

Log.d(
"UnsupportedEncodingException ","Resp:\n"+e.getMessage());
e.printStackTrace();
}


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?
javarose is offline  
Reply With Quote
Old October 19th, 2011, 09:33 AM   #5 (permalink)
New Member
 
Join Date: Oct 2011
Posts: 1
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

can anyone tell how to use webservices in android ..suggest any book
harishandro is offline  
Reply With Quote
Reply
Tags
android, app, application, client, client-server, http, json, rest, server, service, soap, wcf, web


Go Back   Android Forums > Android Discussion > Android Applications
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 02:55 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.