Few weeks ago I described how to consume Service Operations implemented in a Mobile Services Custom API for .NET.
In this post I will shortly describe one additional overload of helper Method “InvokeApiAsync”
By using of that method it is also possible to easily pass a complex type argument as input in the message payload.
Following code-snippet shows how to do that:
Order order = new Order() { Id = 1, Amount = 100, ProductName = "Product 1" };
JToken jOrder = JToken.FromObject(order);
JToken jOrderResult = await App.MobileService.InvokeApiAsync("Order", jOrder, HttpMethod.Post,
new Dictionary<string, string>() { { "prodName", "Prod" } });
In this example we use a JToken type. First we create the order and then JToken from it. Result is retrieved as a JToken.
The service operation looks like shown below. For more details about this API please take a look on a previous post.
[HttpPost] public Order PostOrder(Order order) { if (order == null) return null; var existingOrder = m_Orders.FirstOrDefault(o=>o.Id == order.Id); if (existingOrder != null) { existingOrder = order; return order; } else return null; }
|
Posted
May 06 2014, 08:31 AM
by
Damir Dobric