Sunday, January 12, 2014

Consuming Custom API of Azure Mobile Services

In the last post we’ve seen how to create Custom API in Azure mobile service. Here in, we will see how to consume it in a windows phone 8 application.
First of all, we need to create the mobile service client as:

   1: public static MobileServiceClient MobileService = new MobileServiceClient(
   2:     "https://neeleshservice.azure-mobile.net/",
   3:     "<App Key>"
   4: );

Next is to make the GET call to the api as:


   1: public async void APICall()
   2: {
   3:    JToken response = 
   4:       await MobileService.InvokeApiAsync("neeleshcustomapi",HttpMethod.Get,null);
   5:    var result = 
   6:       Newtonsoft.Json.JsonConvert.DeserializeObject<Message>(response.ToString());
   7:    MessageBox.Show(result.message);
   8: }

The API that we are calling return JSON. We need to parse the JSON in order to extract the  content of the response. In order to parse the JSON, we first need to materialize the response. For that I have created a class Message and deserialized the response into a very instance of this class.


   1: public class Message
   2: {
   3:     public string message { get; set; }
   4: }

Incorporate the code into the application, and run it. You will see a message box poping up, showing the response from the API.

Share this post

0 comments

:) :-) :)) =)) :( :-( :(( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ :-$ (b) (f) x-) (k) (h) (c) cheer

 
© 2013 Neelesh Vishwakarma
Posts RSS Comments RSS
Back to top