Announcement Announcement Module
Collapse
No announcement yet.
Newbie: get an object array sending their IDs using Spring Framework for Android Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Newbie: get an object array sending their IDs using Spring Framework for Android

    I'm very very newbie on JSON web services and Spring Framework for Android.

    I'm developing an Android 2.2 application using Spring Framework for Android 1.0RC1 and also I'm developing JSON web services using WCF, C# and .Net Framework 4.0.

    I have developed successfully a web service to retrieve an array of custom objects with this endpoint:

    WCF code:

    Code:
    [ServiceContract]
        public interface IRestServiceImpl
        {
            [OperationContract]
            [WebInvoke(Method = "GET",
                ResponseFormat = WebMessageFormat.Json,
                BodyStyle = WebMessageBodyStyle.Bare,
                UriTemplate = "orders/")]
            OrderContract[] allOrders();
        }
    Android code:

    Code:
    public static ArrayList<Order> LoadAll(String url)
        {
        	Log.v("OrderSpringController", "LoadAll");
        	try
        	{
        		HttpHeaders requestHeaders = new HttpHeaders();
        		requestHeaders.setAccept(Collections.singletonList(new MediaType("application","json")));
        		HttpEntity<?> requestEntity = new HttpEntity<Object>(requestHeaders);
        
        		GsonHttpMessageConverter messageConverter = new GsonHttpMessageConverter();
        		List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
        		messageConverters.add(messageConverter);
        
        		HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
        		requestFactory.setReadTimeout(60000);
        
                RestTemplate restTemplate = new RestTemplate(requestFactory);
                restTemplate.setMessageConverters(messageConverters);
        
                ResponseEntity<Order[]> responseEntity = restTemplate.exchange(url, HttpMethod.GET, requestEntity, Order[].class);
                Order[] result= responseEntity.getBody();
             
                return new ArrayList<Order>(Arrays.asList(result));
        	}
        	catch (Exception e)
        	{
        		e.printStackTrace();
        	}
        
        	return null;
        }
    And it works!!!

    Now I need to do the same but I need to make a GET sending an int[]. This array will contain a set of Order's ids.

    I now, I can do something like that on WCF:

    Code:
    [OperationContract]
        [WebInvoke(Method = "GET",
            ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Bare,
            UriTemplate = "orders/{orderId}")]
        OrderContract getOrder(String orderId);
    But, I don't want to make a call for each id.

    How can I send an `int[]` from Android?
    How can I get this `int[]` on WCF?

    If you know some tutorial about how to do it, I will thank you.
Working...
X