Question

I am using azure mobile services and I have the following code on the server:

  request.respond(statusCodes.OK, "success");

On my windows store app I have:

await App.MobileService.GetTable<UserEntity>().InsertAsync(App.CurrentUser);

How can I retrieve the body message?

Was it helpful?

Solution

The mobile services client, expects the response content from a table call to return JSON on success. It will attempt to deserialize the response into the requested object (UserEntity) and mutate the item you passed in if successful.

Since the string you are returning ("success") is probably not able to be deserialized into a UserEntity object, I'd expect the insertAsync() to throw an error on along the lines of "Newtonsoft reader, unexpected character encountered..."

If you update your request.respond() to return a valid json packet like { name: 'username', address: '123 Home' }, etc then your App.CurrentUser object would be updated to reflect those changes.

note: If you're not seeing the above error, double check that your call to request.respond() is in the request.execute() success callback. You may be trying to write to the response a second time, and that second time will fail (and should be visible in your app's logs)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top