Kuldeep
Kuldeep

Reputation: 509

how to collect response for azure mobile service call from windows phone 8 application

i am using azure mobile service in my windows phone application, while inserting data in the user table i use the below service call.

private async void SaveUser()
{
   try
   {
     await UserTable.InsertAsync(UserObject);
   }
   catch (MobileServiceInvalidOperationException ex)
   {

   }
}

in case of success how to collect the response of the above service call

Upvotes: 0

Views: 351

Answers (2)

Simon W
Simon W

Reputation: 5496

InsertAsync should return you a type of Task which you can do all sorts of magic with (like the following to check to see if the actual call resulted in a Fault).

var serviceCall = UserTable.InsertAsync(userObject);

await serviceCall;

if(serviceCall.IsFaulted)
{
success = false;
}

Upvotes: 0

carlosfigueira
carlosfigueira

Reputation: 87218

In case of success the object you passed to the InsertAsync call will have been modified. See an example in the code below:

private async Task SaveUser()
{
    try
    {
        var userObject = new UserObject { Name = "Scooby Doo", Age = 11 };
        await UserTable.InsertAsync(userObject);
        var objId = userObject.Id;
        Trace("The id of the object is {0}", objId);
    }
    catch (MobileServiceInvalidOperationException ex)
    {
    }
}

public class UserObject
{
    public int Id { get; set; }
    public string Name { get; set; }
    public int Age { get; set; }
}

Upvotes: 1

Related Questions