簡體   English   中英

在客戶端中更改Azure移動應用程序服務URL

[英]Change Azure Mobile App service url in client

我已經升級了后端服務以使用Azure Mobie App SDK並支持OData查詢。 我使用郵遞員發出請求,並收到所需的回復。 一切正常。 現在,我想升級客戶端以使用Azure移動應用程序SDK。 我面臨的問題是客戶端SDK在生成的URL中使用了硬編碼 這段代碼:

class SiteRepository
{
    private MobileServiceClient client;
    private IMobileServiceSyncTable<Site> siteTable;

    private SiteRepository()
    {
        client = new MobileServiceClient("http://{{host}}/");
        Task.Run(() => InitLocalStoreAsync());
        siteTable = client.GetSyncTable<Site>();

        siteTable.PullAsync("Site", siteTable.CreateQuery());
    }

    private async Task InitLocalStoreAsync()
    {
        if (!client.SyncContext.IsInitialized)
        {
            var store = new MobileServiceSQLiteStore("localstore.db");
            store.DefineTable<Site>();
            await client.SyncContext.InitializeAsync(store);
        }
    }

    public List<Site> GetSites()
    {
        return Task.Run(() => siteTable.ToListAsync()).Result;
    }

發送請求到:

GET http://{{host}}/tables/site$filter=(updatedAt%20ge ...

但我希望它將請求發送到:

GET http://{{host}}/api/local/sites?$filter=(updatedAt%20ge...

我可以以某種方式將tables部分更改為其他內容嗎?

更新

這是后端上的SiteController

[RoutePrefix("api/local/sites")]
[MobileAppController]
public class SiteController<T> : TableController<T> where T : Model.Entity
{
    protected SiteService<T> service;
    public BaseController(IEntityService<T> _service) 
    {
        service = _service;
    }

    [Route("")]
    [HttpGet]
    [EnableQuery]
    public virtual IQueryable<T> Get()
    {
        var entities = service.GetAll();
        if (entities == null || entities.Count() == 0)
        {
            return null;
        }

        return TableUtils.ApplyDeletedFilter(entities.AsQueryable(), Request.AreDeletedRowsRequested());
    }

對於IMobileServiceTable和IMobileServiceSyncTable,請求始終使用/ tables端點。 若要更改此行為,請將委派處理程序附加到MobileServiceClient並在發送請求之前更改請求URI。

這是一個進行日志記錄的委托處理程序的示例,其中顯示了將代碼添加到的位置: 在移動客戶端中記錄傳出的請求

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM