InvokeApiAsync <httpresponsemessage>返回null

时间:2016-11-18 22:49:13

标签: azure-mobile-services

有人可以解释为什么客户端(Xamarin.Forms PCL)调用返回null吗?

HttpResponseMessage response = await OfflineSyncStoreManager.Instance.MobileAppClient.InvokeApiAsync<HttpResponseMessage>("ResetTruckAuftragWorkflow");
  

响应 null 。当我在控制台应用程序中执行它时,它返回   有效的http响应。

我在客户端和后端使用最新的稳定ZUMO nugets。有我的ZUMO后端代码:

[Authorize]
[MobileAppController]
public class ResetTruckAuftragWorkflowController : ApiController
{
    private readonly RcsMobileContext _rcsMobileContext;
    private readonly TruckFahrerInfo _truckFahrerInfo;


    public ResetTruckAuftragWorkflowController()
    {
        _rcsMobileContext = new RcsMobileContext();
        _truckFahrerInfo = new TruckFahrerInfo(this.User as ClaimsPrincipal);
    }

    // POST api/ResetTruckAuftragWorkflow
    [HttpPost]
    public async Task<IHttpActionResult> PostAsync()
    {
        if (ModelState.IsValid)
        {
            using (var transaction = _rcsMobileContext.Database.BeginTransaction())
            {
                try
                {
                    var truckAuftragList = _rcsMobileContext.TruckAuftrags.PerUserFilter(_truckFahrerInfo.FahrerId);
                    var truckAppIds = truckAuftragList?.Select(ta => ta.TruckAppId).ToArray();

                    if (truckAppIds != null)
                    {
                        foreach (var truckAppId in truckAppIds)
                        {
                            await _rcsMobileContext.Database.ExecuteSqlCommandAsync(_tawQueryTaskStatus10, truckAppId);
                            await _rcsMobileContext.Database.ExecuteSqlCommandAsync(_tawQueryTaskStatus5, truckAppId);
                            await _rcsMobileContext.Database.ExecuteSqlCommandAsync(_talQuery, truckAppId);
                            await _rcsMobileContext.Database.ExecuteSqlCommandAsync(_taQuery, truckAppId);
                        }
                    }

                    await _rcsMobileContext.Database.ExecuteSqlCommandAsync(_taQuery, _truckFahrerInfo.FahrerId);

                    transaction.Commit();
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    return BadRequest($"Transaction failed: {e}");
                }
            }

            return Ok();
        }
        else
        {
            return BadRequest(ModelState);
        }
    }

    protected override void Dispose(bool disposing)
    {
        if (disposing)
        {
            _rcsMobileContext.Dispose();
        }

        base.Dispose(disposing);
    }
}

感谢

埃里克

1 个答案:

答案 0 :(得分:0)

InvokeApiAsync对返回的主体进行解码,并将JSON反序列化为类型T.您不应将HttpResponseMessage用于此目的,因为它不可序列化。

如果您不关心身体,请使用非泛型形式的InvokeApiAsync。