使用Azure Mobile Client for Rest API

问题描述 投票:0回答:1

我开始使用Azure Mobile App SDK开发我的Xamarin应用程序。从TableControlle开始,但由于希望在API中保留大多数业务逻辑,最终使用REST概念来支持大多数服务。例如。 :

        [MyAuthorize(ActivityEnum.None, UserRole.Admin)]
    [HttpGet]
    [Route("GetOrderByUser")]
    public IHttpActionResult GetOrderByUser(int tenantID, string userID)
    {
        try
        {
            var Orders = db.Orders
                    .Where(x => x.TenantID == tenantID && x.DateEndShip == null && x.DateCancel == null)
                    .Project().To<OrderDto>()
                    .ToList();

            foreach (var item in Orders)
            {
                item.CustomerName = db.Parties.FirstOrDefault(x => x.ID == item.CustomerID).Name;
                item.Order_Lines = db.Order_Line.Where(x => x.OrderID == item.OrderID)
                                    .Project()
                                    .To<Order_LineDto>()
                                    .ToList();
                foreach (var line in item.Order_Lines)
                {
                    line.ItemName = db.Items.FirstOrDefault(x => x.ID == line.ItemID).ItemID;
                }
            }

            return Ok(Orders);
        }
        catch (Exception ex)
        {
            return ResponseMessage(Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message));
        }
    }

所以在Xamarin中使用了HTTPClient。但我认为这往往是不稳定的,并且会破坏Azure移动应用服务托管的目的。此外,授权变得混乱,因为我需要在URL中传递令牌。

我是否可以使用Azure Mobile App SDK来调用此服务?

azure-mobile-services
1个回答
0
投票

Azure移动应用客户端SDK提供对Azure移动应用服务器SDK的客户端访问。你需要串联使用这两个。你不能在不使用另一个的情况下使用它。

由于您使用的是Xamarin,请查看https://adrianhall.gitlab.io/develop-mobile-apps-with-csharp-and-azure/上的书籍 - 本书中介绍了很多概念。

© www.soinside.com 2019 - 2024. All rights reserved.